WIP: PUT /api/v1/media/:id

This commit is contained in:
Alex Gleason 2023-09-10 14:09:11 -05:00
parent b9476ccbd6
commit bace1e9562
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 33 additions and 2 deletions

View file

@ -1,11 +1,12 @@
import { AppController } from '@/app.ts';
import { Conf } from '@/config.ts';
import { insertUnattachedMedia } from '@/db/unattached-media.ts';
import { getUnattachedMediaForUser, insertUnattachedMedia } from '@/db/unattached-media.ts';
import { z } from '@/deps.ts';
import { fileSchema } from '@/schema.ts';
import { configUploader as uploader } from '@/uploaders/config.ts';
import { parseBody } from '@/utils/web.ts';
import { renderAttachment } from '@/views/attachment.ts';
import { jsonMediaDataSchema } from '@/schemas/nostr.ts';
const uploadSchema = fileSchema
.refine((file) => !!file.type, 'File type is required.')
@ -49,4 +50,25 @@ const mediaController: AppController = async (c) => {
}
};
export { mediaController };
const updateMediaController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const mediaId = c.req.param('id');
const media = await getUnattachedMediaForUser(pubkey, mediaId);
if (!media) {
return c.json({ error: 'Media not found.' }, 404);
}
const result = mediaBodySchema.safeParse(await parseBody(c.req.raw));
if (!result.success) {
return c.json({ error: 'Bad request.', schema: result.error }, 422);
}
const data = jsonMediaDataSchema.parse(media.data);
};
export { mediaController, updateMediaController };

View file

@ -59,6 +59,14 @@ function getUnattachedMediaByIds(ids: string[]) {
.execute();
}
/** Get a single media with an ID and a user. */
function getUnattachedMediaForUser(pubkey: string, id: string) {
return selectUnattachedMediaQuery()
.where('pubkey', '=', pubkey)
.where('id', '=', id)
.executeTakeFirst();
}
/** Delete rows as an event with media is being created. */
function deleteAttachedMedia(pubkey: string, urls: string[]) {
return db.deleteFrom('unattached_media')
@ -73,5 +81,6 @@ export {
getUnattachedMedia,
getUnattachedMediaByIds,
insertUnattachedMedia,
getUnattachedMediaForUser,
type UnattachedMedia,
};