mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-24 15:54:23 +01:00
media: pukey --> pubkey, fix adding media tags to event
This commit is contained in:
@@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.createTable('unattached_media')
|
||||
.addColumn('id', 'text', (c) => c.primaryKey())
|
||||
.addColumn('pukey', 'text', (c) => c.notNull())
|
||||
.addColumn('pubkey', 'text', (c) => c.notNull())
|
||||
.addColumn('url', 'text', (c) => c.notNull())
|
||||
.addColumn('data', 'text', (c) => c.notNull())
|
||||
.addColumn('uploaded_at', 'datetime', (c) => c.notNull().defaultTo(sql`CURRENT_TIMESTAMP`))
|
||||
@@ -17,9 +17,9 @@ export async function up(db: Kysely<any>): Promise<void> {
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('unattached_media_pukey')
|
||||
.createIndex('unattached_media_pubkey')
|
||||
.on('unattached_media')
|
||||
.column('pukey')
|
||||
.column('pubkey')
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
|
||||
@@ -3,7 +3,7 @@ import { uuid62 } from '@/deps.ts';
|
||||
|
||||
interface UnattachedMedia {
|
||||
id: string;
|
||||
pukey: string;
|
||||
pubkey: string;
|
||||
url: string;
|
||||
data: {
|
||||
name?: string;
|
||||
@@ -16,15 +16,18 @@ interface UnattachedMedia {
|
||||
uploaded_at: Date;
|
||||
}
|
||||
|
||||
function insertUnattachedMedia(media: Omit<UnattachedMedia, 'id' | 'uploaded_at'>) {
|
||||
return db.insertInto('unattached_media')
|
||||
.values({
|
||||
id: uuid62.v4(),
|
||||
uploaded_at: new Date(),
|
||||
...media,
|
||||
data: JSON.stringify(media.data),
|
||||
})
|
||||
async function insertUnattachedMedia(media: Omit<UnattachedMedia, 'id' | 'uploaded_at'>) {
|
||||
const result = {
|
||||
id: uuid62.v4(),
|
||||
uploaded_at: new Date(),
|
||||
...media,
|
||||
};
|
||||
|
||||
await db.insertInto('unattached_media')
|
||||
.values({ ...result, data: JSON.stringify(media.data) })
|
||||
.execute();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Find attachments that exist but aren't attached to any events. */
|
||||
@@ -32,7 +35,7 @@ function getUnattachedMedia(until: Date) {
|
||||
return db.selectFrom('unattached_media')
|
||||
.select([
|
||||
'unattached_media.id',
|
||||
'unattached_media.pukey',
|
||||
'unattached_media.pubkey',
|
||||
'unattached_media.url',
|
||||
'unattached_media.data',
|
||||
'unattached_media.uploaded_at',
|
||||
@@ -48,4 +51,17 @@ function deleteUnattachedMediaByUrl(url: string) {
|
||||
.execute();
|
||||
}
|
||||
|
||||
export { deleteUnattachedMediaByUrl, getUnattachedMedia, insertUnattachedMedia };
|
||||
function getUnattachedMediaByIds(ids: string[]) {
|
||||
return db.selectFrom('unattached_media')
|
||||
.select([
|
||||
'unattached_media.id',
|
||||
'unattached_media.pubkey',
|
||||
'unattached_media.url',
|
||||
'unattached_media.data',
|
||||
'unattached_media.uploaded_at',
|
||||
])
|
||||
.where('id', 'in', ids)
|
||||
.execute();
|
||||
}
|
||||
|
||||
export { deleteUnattachedMediaByUrl, getUnattachedMedia, getUnattachedMediaByIds, insertUnattachedMedia };
|
||||
|
||||
Reference in New Issue
Block a user