mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
Begin work on media attachments
This commit is contained in:
parent
97af3bc2d0
commit
580958a181
7 changed files with 184 additions and 2 deletions
47
database/entities/Attachment.ts
Normal file
47
database/entities/Attachment.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { ConfigType } from "@config";
|
||||
import { Attachment } from "@prisma/client";
|
||||
import { APIAsyncAttachment } from "~types/entities/async_attachment";
|
||||
import { APIAttachment } from "~types/entities/attachment";
|
||||
|
||||
export const attachmentToAPI = (
|
||||
attachment: Attachment
|
||||
): APIAsyncAttachment | APIAttachment => {
|
||||
let type = "unknown";
|
||||
|
||||
if (attachment.mime_type.startsWith("image/")) {
|
||||
type = "image";
|
||||
} else if (attachment.mime_type.startsWith("video/")) {
|
||||
type = "video";
|
||||
} else if (attachment.mime_type.startsWith("audio/")) {
|
||||
type = "audio";
|
||||
}
|
||||
|
||||
return {
|
||||
id: attachment.id,
|
||||
type: type as any,
|
||||
url: attachment.url,
|
||||
remote_url: attachment.remote_url,
|
||||
preview_url: attachment.thumbnail_url,
|
||||
text_url: null,
|
||||
meta: {
|
||||
width: attachment.width || undefined,
|
||||
height: attachment.height || undefined,
|
||||
fps: attachment.fps || undefined,
|
||||
size: attachment.size?.toString() || undefined,
|
||||
duration: attachment.duration || undefined,
|
||||
length: attachment.size?.toString() || undefined,
|
||||
// Idk whether size or length is the right value
|
||||
},
|
||||
description: attachment.description,
|
||||
blurhash: attachment.blurhash,
|
||||
};
|
||||
};
|
||||
|
||||
export const getUrl = (hash: string, config: ConfigType) => {
|
||||
if (config.media.backend === "local") {
|
||||
return `${config.http.base_url}/media/${hash}`;
|
||||
} else if (config.media.backend === "s3") {
|
||||
return `${config.s3.public_url}/${hash}`;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue