refactor(database): 🚚 Rename "Attachment" to "Media"

This commit is contained in:
Jesse Wierzbinski 2025-01-23 16:08:42 +01:00
parent bbd56b600d
commit 2f61cd8f0a
No known key found for this signature in database
21 changed files with 2429 additions and 101 deletions

View file

@ -97,7 +97,7 @@ export default apiRoute((app) =>
min_id ? gt(Notes.id, min_id) : undefined,
eq(Notes.authorId, otherUser.id),
only_media
? sql`EXISTS (SELECT 1 FROM "Attachments" WHERE "Attachments"."noteId" = ${Notes.id})`
? sql`EXISTS (SELECT 1 FROM "Medias" WHERE "Medias"."noteId" = ${Notes.id})`
: undefined,
pinned
? sql`EXISTS (SELECT 1 FROM "UserToPinnedNotes" WHERE "UserToPinnedNotes"."noteId" = ${Notes.id} AND "UserToPinnedNotes"."userId" = ${otherUser.id})`

View file

@ -3,7 +3,7 @@ import { mimeLookup } from "@/content_types";
import { mergeAndDeduplicate } from "@/lib";
import { sanitizedHtmlStrip } from "@/sanitization";
import { createRoute } from "@hono/zod-openapi";
import { Attachment, Emoji, User } from "@versia/kit/db";
import { Emoji, Media, User } from "@versia/kit/db";
import { RolePermissions, Users } from "@versia/kit/tables";
import { and, eq, isNull } from "drizzle-orm";
import ISO6391 from "iso-639-1";
@ -251,7 +251,7 @@ export default apiRoute((app) =>
await mediaManager.addFile(avatar);
const contentType = uploadedFile.type;
self.avatar = Attachment.getUrl(path);
self.avatar = Media.getUrl(path);
self.source.avatar = {
content_type: contentType,
};
@ -269,7 +269,7 @@ export default apiRoute((app) =>
await mediaManager.addFile(header);
const contentType = uploadedFile.type;
self.header = Attachment.getUrl(path);
self.header = Media.getUrl(path);
self.source.header = {
content_type: contentType,
};

View file

@ -1,7 +1,7 @@
import { apiRoute, auth, emojiValidator, jsonOrForm } from "@/api";
import { mimeLookup } from "@/content_types";
import { createRoute } from "@hono/zod-openapi";
import { Attachment, Emoji, db } from "@versia/kit/db";
import { Emoji, Media, db } from "@versia/kit/db";
import { Emojis, RolePermissions } from "@versia/kit/tables";
import { eq } from "drizzle-orm";
import { z } from "zod";
@ -270,7 +270,7 @@ export default apiRoute((app) => {
if (element instanceof File) {
const uploaded = await mediaManager.addFile(element);
url = Attachment.getUrl(uploaded.path);
url = Media.getUrl(uploaded.path);
contentType = uploaded.uploadedFile.type;
} else {
url = element;

View file

@ -1,7 +1,7 @@
import { apiRoute, auth, emojiValidator, jsonOrForm } from "@/api";
import { mimeLookup } from "@/content_types";
import { createRoute } from "@hono/zod-openapi";
import { Attachment, Emoji } from "@versia/kit/db";
import { Emoji, Media } from "@versia/kit/db";
import { Emojis, RolePermissions } from "@versia/kit/tables";
import { and, eq, isNull, or } from "drizzle-orm";
import { z } from "zod";
@ -149,7 +149,7 @@ export default apiRoute((app) =>
const uploaded = await mediaManager.addFile(element);
url = Attachment.getUrl(uploaded.path);
url = Media.getUrl(uploaded.path);
contentType = uploaded.uploadedFile.type;
} else {
url = element;

View file

@ -1,6 +1,6 @@
import { apiRoute, auth } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Attachment } from "@versia/kit/db";
import { Media } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import { z } from "zod";
import { ApiError } from "~/classes/errors/api-error";
@ -48,7 +48,7 @@ const routePut = createRoute({
description: "Media updated",
content: {
"application/json": {
schema: Attachment.schema,
schema: Media.schema,
},
},
},
@ -82,7 +82,7 @@ const routeGet = createRoute({
description: "Media",
content: {
"application/json": {
schema: Attachment.schema,
schema: Media.schema,
},
},
},
@ -101,7 +101,7 @@ export default apiRoute((app) => {
app.openapi(routePut, async (context) => {
const { id } = context.req.valid("param");
const attachment = await Attachment.fromId(id);
const attachment = await Media.fromId(id);
if (!attachment) {
throw new ApiError(404, "Media not found");
@ -115,7 +115,7 @@ export default apiRoute((app) => {
if (thumbnail) {
const { path } = await mediaManager.addFile(thumbnail);
thumbnailUrl = Attachment.getUrl(path);
thumbnailUrl = Media.getUrl(path);
}
const descriptionText = description || attachment.data.description;
@ -138,7 +138,7 @@ export default apiRoute((app) => {
app.openapi(routeGet, async (context) => {
const { id } = context.req.valid("param");
const attachment = await Attachment.fromId(id);
const attachment = await Media.fromId(id);
if (!attachment) {
throw new ApiError(404, "Media not found");

View file

@ -1,6 +1,6 @@
import { apiRoute, auth } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Attachment } from "@versia/kit/db";
import { Media } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import { z } from "zod";
import { config } from "~/packages/config-manager/index.ts";
@ -43,7 +43,7 @@ const route = createRoute({
description: "Attachment",
content: {
"application/json": {
schema: Attachment.schema,
schema: Media.schema,
},
},
},
@ -71,7 +71,7 @@ export default apiRoute((app) =>
app.openapi(route, async (context) => {
const { file, thumbnail, description } = context.req.valid("form");
const attachment = await Attachment.fromFile(file, {
const attachment = await Media.fromFile(file, {
thumbnail,
description,
});

View file

@ -1,6 +1,6 @@
import { apiRoute, auth, jsonOrForm, withNoteParam } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Attachment, Note } from "@versia/kit/db";
import { Media, Note } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import ISO6391 from "iso-639-1";
import { z } from "zod";
@ -246,7 +246,7 @@ export default apiRoute((app) => {
} = context.req.valid("json");
const foundAttachments =
media_ids.length > 0 ? await Attachment.fromIds(media_ids) : [];
media_ids.length > 0 ? await Media.fromIds(media_ids) : [];
if (foundAttachments.length !== media_ids.length) {
throw new ApiError(

View file

@ -1,6 +1,6 @@
import { apiRoute, auth, jsonOrForm } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Attachment, Note } from "@versia/kit/db";
import { Media, Note } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import ISO6391 from "iso-639-1";
import { z } from "zod";
@ -151,7 +151,7 @@ export default apiRoute((app) =>
// Check if media attachments are all valid
const foundAttachments =
media_ids.length > 0 ? await Attachment.fromIds(media_ids) : [];
media_ids.length > 0 ? await Media.fromIds(media_ids) : [];
if (foundAttachments.length !== media_ids.length) {
throw new ApiError(

View file

@ -74,7 +74,7 @@ export default apiRoute((app) =>
? sql`EXISTS (SELECT 1 FROM "Users" WHERE "Users"."id" = ${Notes.authorId} AND "Users"."instanceId" IS NULL)`
: undefined,
only_media
? sql`EXISTS (SELECT 1 FROM "Attachments" WHERE "Attachments"."noteId" = ${Notes.id})`
? sql`EXISTS (SELECT 1 FROM "Medias" WHERE "Medias"."noteId" = ${Notes.id})`
: undefined,
user
? sql`NOT EXISTS (SELECT 1 FROM "Filters" WHERE "Filters"."userId" = ${user.id} AND "Filters"."filter_action" = 'hide' AND EXISTS (SELECT 1 FROM "FilterKeywords" WHERE "FilterKeywords"."filterId" = "Filters"."id" AND "Notes"."content" LIKE '%' || "FilterKeywords"."keyword" || '%') AND "Filters"."context" @> ARRAY['public'])`

View file

@ -1,6 +1,6 @@
import { apiRoute, auth } from "@/api";
import { createRoute } from "@hono/zod-openapi";
import { Attachment } from "@versia/kit/db";
import { Media } from "@versia/kit/db";
import { RolePermissions } from "@versia/kit/tables";
import { z } from "zod";
import { config } from "~/packages/config-manager/index.ts";
@ -43,7 +43,7 @@ const route = createRoute({
description: "Uploaded media",
content: {
"application/json": {
schema: Attachment.schema,
schema: Media.schema,
},
},
},
@ -70,7 +70,7 @@ export default apiRoute((app) =>
app.openapi(route, async (context) => {
const { file, thumbnail, description } = context.req.valid("form");
const attachment = await Attachment.fromFile(file, {
const attachment = await Media.fromFile(file, {
thumbnail,
description,
});