mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
WIP: PUT /api/v1/media/:id
This commit is contained in:
parent
b9476ccbd6
commit
bace1e9562
2 changed files with 33 additions and 2 deletions
|
|
@ -1,11 +1,12 @@
|
||||||
import { AppController } from '@/app.ts';
|
import { AppController } from '@/app.ts';
|
||||||
import { Conf } from '@/config.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 { z } from '@/deps.ts';
|
||||||
import { fileSchema } from '@/schema.ts';
|
import { fileSchema } from '@/schema.ts';
|
||||||
import { configUploader as uploader } from '@/uploaders/config.ts';
|
import { configUploader as uploader } from '@/uploaders/config.ts';
|
||||||
import { parseBody } from '@/utils/web.ts';
|
import { parseBody } from '@/utils/web.ts';
|
||||||
import { renderAttachment } from '@/views/attachment.ts';
|
import { renderAttachment } from '@/views/attachment.ts';
|
||||||
|
import { jsonMediaDataSchema } from '@/schemas/nostr.ts';
|
||||||
|
|
||||||
const uploadSchema = fileSchema
|
const uploadSchema = fileSchema
|
||||||
.refine((file) => !!file.type, 'File type is required.')
|
.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 };
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,14 @@ function getUnattachedMediaByIds(ids: string[]) {
|
||||||
.execute();
|
.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. */
|
/** Delete rows as an event with media is being created. */
|
||||||
function deleteAttachedMedia(pubkey: string, urls: string[]) {
|
function deleteAttachedMedia(pubkey: string, urls: string[]) {
|
||||||
return db.deleteFrom('unattached_media')
|
return db.deleteFrom('unattached_media')
|
||||||
|
|
@ -73,5 +81,6 @@ export {
|
||||||
getUnattachedMedia,
|
getUnattachedMedia,
|
||||||
getUnattachedMediaByIds,
|
getUnattachedMediaByIds,
|
||||||
insertUnattachedMedia,
|
insertUnattachedMedia,
|
||||||
|
getUnattachedMediaForUser,
|
||||||
type UnattachedMedia,
|
type UnattachedMedia,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue