diff --git a/keyserver/src/creators/farcaster-channel-tag-creator.js b/keyserver/src/creators/farcaster-channel-tag-creator.js index 3c9f75e73..2982d309a 100644 --- a/keyserver/src/creators/farcaster-channel-tag-creator.js +++ b/keyserver/src/creators/farcaster-channel-tag-creator.js @@ -1,94 +1,93 @@ // @flow import uuid from 'uuid'; -import { DISABLE_TAGGING_FARCASTER_CHANNEL } from 'lib/shared/community-utils.js'; +import { + DISABLE_TAGGING_FARCASTER_CHANNEL, + farcasterChannelTagBlobHash, +} from 'lib/shared/community-utils.js'; import type { CreateOrUpdateFarcasterChannelTagRequest, CreateOrUpdateFarcasterChannelTagResponse, } from 'lib/types/community-types.js'; import { ServerError } from 'lib/utils/errors.js'; import { uploadBlob, assignHolder, download, type BlobOperationResult, type BlobDownloadResult, } from '../services/blob.js'; import { Viewer } from '../session/viewer.js'; async function createOrUpdateFarcasterChannelTag( viewer: Viewer, request: CreateOrUpdateFarcasterChannelTagRequest, ): Promise { const { commCommunityID, farcasterChannelID } = request; if (DISABLE_TAGGING_FARCASTER_CHANNEL) { throw new ServerError('internal_error'); } const blobDownload = await getFarcasterChannelTagBlob(farcasterChannelID); if (blobDownload.found) { throw new ServerError('already_in_use'); } const blobHolder = uuid.v4(); const blobResult = await uploadFarcasterChannelTagBlob( commCommunityID, farcasterChannelID, blobHolder, ); if (!blobResult.success) { if (blobResult.reason === 'HASH_IN_USE') { throw new ServerError('already_in_use'); } else { throw new ServerError('unknown_error'); } } return { commCommunityID, blobHolder, }; } -function farcasterChannelTagBlobHash(secret: string): string { - return `farcaster_channel_tag_${secret}`; -} - function getFarcasterChannelTagBlob( secret: string, ): Promise { const hash = farcasterChannelTagBlobHash(secret); return download(hash); } async function uploadFarcasterChannelTagBlob( commCommunityID: string, farcasterChannelID: string, holder: string, ): Promise { const payload = { commCommunityID, farcasterChannelID, }; const payloadString = JSON.stringify(payload); const hash = farcasterChannelTagBlobHash(farcasterChannelID); const blob = new Blob([payloadString]); const uploadResult = await uploadBlob(blob, hash); if (!uploadResult.success) { return uploadResult; } return await assignHolder({ holder, hash }); } export { createOrUpdateFarcasterChannelTag, uploadFarcasterChannelTagBlob }; diff --git a/keyserver/src/deleters/farcaster-channel-tag-deleters.js b/keyserver/src/deleters/farcaster-channel-tag-deleters.js new file mode 100644 index 000000000..877b26127 --- /dev/null +++ b/keyserver/src/deleters/farcaster-channel-tag-deleters.js @@ -0,0 +1,32 @@ +// @flow + +import { + DISABLE_TAGGING_FARCASTER_CHANNEL, + farcasterChannelTagBlobHash, +} from 'lib/shared/community-utils.js'; +import type { DeleteFarcasterChannelTagRequest } from 'lib/types/community-types'; +import { ServerError } from 'lib/utils/errors.js'; + +import { deleteBlob } from '../services/blob.js'; +import type { Viewer } from '../session/viewer'; + +async function deleteFarcasterChannelTag( + viewer: Viewer, + request: DeleteFarcasterChannelTagRequest, +): Promise { + const { farcasterChannelID, blobHolder } = request; + + if (DISABLE_TAGGING_FARCASTER_CHANNEL) { + throw new ServerError('internal_error'); + } + + await deleteBlob( + { + hash: farcasterChannelTagBlobHash(farcasterChannelID), + holder: blobHolder, + }, + true, + ); +} + +export { deleteFarcasterChannelTag }; diff --git a/lib/shared/community-utils.js b/lib/shared/community-utils.js index 3c25673f1..c4852f8aa 100644 --- a/lib/shared/community-utils.js +++ b/lib/shared/community-utils.js @@ -1,5 +1,9 @@ // @flow const DISABLE_TAGGING_FARCASTER_CHANNEL = true; -export { DISABLE_TAGGING_FARCASTER_CHANNEL }; +function farcasterChannelTagBlobHash(farcasterChannelID: string): string { + return `farcaster_channel_tag_${farcasterChannelID}`; +} + +export { DISABLE_TAGGING_FARCASTER_CHANNEL, farcasterChannelTagBlobHash }; diff --git a/lib/types/community-types.js b/lib/types/community-types.js index d7612c5db..c572853ef 100644 --- a/lib/types/community-types.js +++ b/lib/types/community-types.js @@ -1,28 +1,34 @@ // @flow import type { EnabledApps } from './enabled-apps.js'; export type CommunityInfo = { +enabledApps: EnabledApps, }; export type CommunityInfos = { +[threadID: string]: CommunityInfo }; export type CommunityStore = { +communityInfos: CommunityInfos, }; export type AddCommunityPayload = { +id: string, +newCommunityInfo: CommunityInfo, }; export type CreateOrUpdateFarcasterChannelTagRequest = { +commCommunityID: string, +farcasterChannelID: string, }; export type CreateOrUpdateFarcasterChannelTagResponse = { +commCommunityID: string, +blobHolder: string, }; + +export type DeleteFarcasterChannelTagRequest = { + +commCommunityID: string, + +farcasterChannelID: string, + +blobHolder: string, +};