Clone attachment to other piece
This commit is contained in:
@@ -316,14 +316,26 @@ export const handle = implement(api, {
|
||||
const { userId } = yield* requireOneOf(WRITE_ACCESS);
|
||||
const db = yield* Database.Database;
|
||||
|
||||
const sha256 = Sha256.make(new Uint8Array(Bun.SHA256.byteLength));
|
||||
Bun.SHA256.hash(attachment.data, sha256);
|
||||
let sha256: Sha256;
|
||||
if ("sha256" in attachment) {
|
||||
sha256 = attachment.sha256;
|
||||
|
||||
yield* db
|
||||
.insertInto("File")
|
||||
.values({ sha256, data: attachment.data })
|
||||
.onConflict((cb) => cb.column("sha256").doNothing())
|
||||
.$call(Database.execute);
|
||||
yield* db
|
||||
.selectFrom("File")
|
||||
.select("sha256")
|
||||
.where("sha256", "=", sha256)
|
||||
.$call(Database.executeTakeFirst)
|
||||
.pipe(Effect.mapError(() => NotFound.make()));
|
||||
} else {
|
||||
sha256 = Sha256.make(new Uint8Array(Bun.SHA256.byteLength));
|
||||
Bun.SHA256.hash(attachment.data, sha256);
|
||||
|
||||
yield* db
|
||||
.insertInto("File")
|
||||
.values({ sha256, data: attachment.data })
|
||||
.onConflict((cb) => cb.column("sha256").doNothing())
|
||||
.$call(Database.execute);
|
||||
}
|
||||
|
||||
const res = yield* db
|
||||
.insertInto("Attachment")
|
||||
|
||||
Reference in New Issue
Block a user