Skip to content

Commit

Permalink
Merge pull request #110 from ixofoundation/develop
Browse files Browse the repository at this point in the history
feat: add temp dynamic key public doc
  • Loading branch information
Michael-Ixo authored Nov 16, 2023
2 parents 4135162 + 3f2ae56 commit b89de03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/handlers/PublicHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const createPublic = async (args: any) => {
if (!fileTypes.includes(args.contentType)) {
return 'Invalid File Type';
}
return PublicService.createPublic(args.contentType, args.data);
return PublicService.createPublic(args.contentType, args.data, args.key);
};

export const fetchPublic = async (args: any) => {
Expand Down
15 changes: 14 additions & 1 deletion src/services/PublicService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@ import Hash from 'ipfs-only-hash';
// const { v5: uuidv5 } = require('uuid');
// const uuidv5CellnodeNamespace = 'de5047f7-9e83-43c8-85a6-0d19a89c665e';

export const createPublic = async (contentType: string, data: string) => {
export const createPublic = async (contentType: string, data: string, key?: string) => {
// Temporarily store data in db if key is provided, unsafe as can be overwritten by anyone
if (key) {
const keyStartWithTemp = key.startsWith('temp');
if (!keyStartWithTemp) return "key must start with 'temp'";

const base64Data = Buffer.from(data).toString('base64');
return await prisma.public.upsert({
where: { key: key },
update: { contentType: contentType, data: base64Data },
create: { key: key, contentType: contentType, data: base64Data },
});
}

// remove data encoding format eg: "data:*/*;base64," from data
const endOfPrefix = data.indexOf(',');
const cleanData = data.slice(endOfPrefix + 1);
Expand Down

0 comments on commit b89de03

Please sign in to comment.