forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explorer: Image Moderation integration (MystenLabs#2647)
* initial version of image mod service client * lint changes for image mod client * DisplayBox changes for image mod work * remove excess logging * Update imageModeratorClient.ts * tweak blur effect * remove console logs, lint changes * tweak blur css * lint changes * lower blur to fit smaller pages better * change default devnet imgMod port * initial version of image mod service client lint changes for image mod client DisplayBox changes for image mod work remove excess logging Update imageModeratorClient.ts tweak blur effect remove console logs, lint changes tweak blur css lint changes lower blur to fit smaller pages better change default devnet imgMod port general cleanup / css tweaks lint changes * fix up image moderation service host * lint change * slow down hiding blur animation * revert stray css change * add missing license * add fallback image * add fallback image var * rename blur related vars * show automod notice in middle of image * lint change * remove image display when auto-modded * Update DisplayBox.module.css * don't show image before approval in explorer * tweak automod text notice * remove excess styling in displaybox * make automod notice smaller * update img check response format * lint changes * rearrange logic for automod notice * lint changes
- Loading branch information
Stella Cannefax
authored
Jul 14, 2022
1 parent
817d799
commit 5dede27
Showing
5 changed files
with
128 additions
and
30 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { IS_LOCAL_ENV, IS_STATIC_ENV } from './envUtil'; | ||
|
||
const ENV_STUBS_IMG_CHECK = IS_STATIC_ENV || IS_LOCAL_ENV; | ||
const HOST = 'https://imgmod.sui.io'; | ||
|
||
export type ImageCheckResponse = { ok: boolean }; | ||
|
||
export interface IImageModClient { | ||
checkImage(url: string): Promise<ImageCheckResponse>; | ||
} | ||
|
||
export class ImageModClient implements IImageModClient { | ||
private readonly imgEndpoint: string; | ||
|
||
constructor() { | ||
this.imgEndpoint = `${HOST}/img`; | ||
} | ||
|
||
async checkImage(url: string): Promise<ImageCheckResponse> { | ||
// static and local environments always allow images without checking | ||
if (ENV_STUBS_IMG_CHECK || url === FALLBACK_IMAGE) return { ok: true }; | ||
|
||
let resp: Promise<boolean> = ( | ||
await fetch(this.imgEndpoint, { | ||
method: 'POST', | ||
headers: { 'content-type': 'application/json' }, | ||
body: JSON.stringify({ url }), | ||
}) | ||
).json(); | ||
|
||
return { ok: await resp }; | ||
} | ||
} | ||
|
||
export const FALLBACK_IMAGE = 'assets/fallback.png'; |