Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32309149
D11772.1765293812.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D11772.1765293812.diff
View Options
diff --git a/keyserver/src/creators/farcaster-channel-tag-creator.js b/keyserver/src/creators/farcaster-channel-tag-creator.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/creators/farcaster-channel-tag-creator.js
@@ -0,0 +1,89 @@
+// @flow
+
+import uuid from 'uuid';
+
+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<CreateOrUpdateFarcasterChannelTagResponse> {
+ const { commCommunityID, farcasterChannelID } = request;
+
+ 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<BlobDownloadResult> {
+ const hash = farcasterChannelTagBlobHash(secret);
+
+ return download(hash);
+}
+
+async function uploadFarcasterChannelTagBlob(
+ commCommunityID: string,
+ farcasterChannelID: string,
+ holder: string,
+): Promise<BlobOperationResult> {
+ 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/lib/types/community-types.js b/lib/types/community-types.js
--- a/lib/types/community-types.js
+++ b/lib/types/community-types.js
@@ -16,3 +16,13 @@
+id: string,
+newCommunityInfo: CommunityInfo,
};
+
+export type CreateOrUpdateFarcasterChannelTagRequest = {
+ +commCommunityID: string,
+ +farcasterChannelID: string,
+};
+
+export type CreateOrUpdateFarcasterChannelTagResponse = {
+ +commCommunityID: string,
+ +blobHolder: string,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 9, 3:23 PM (13 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5854984
Default Alt Text
D11772.1765293812.diff (2 KB)
Attached To
Mode
D11772: [keyserver] introduce barebones createOrUpdateFarcasterChannelTag
Attached
Detach File
Event Timeline
Log In to Comment