Skip to content

Commit a344930

Browse files
committed
Fix a few schema errors; improve migration script
1 parent 8f81bd6 commit a344930

File tree

17 files changed

+180
-67
lines changed

17 files changed

+180
-67
lines changed

app/api/(utils)/storage.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export class FileStorage implements AppStorage {
6868
releaseId: string,
6969
): Promise<Buffer> {
7070
const fileName = type === "scripts" ? "scripts.zip" : "metadata.json";
71-
return await fs.readFile(`${this.#directory}/modules/${moduleName}/${releaseId}/${fileName}`);
71+
return await fs.readFile(
72+
`${this.#directory}/modules/${moduleName.toLowerCase()}/${releaseId}/${fileName}`,
73+
);
7274
}
7375

7476
async setImage(type: "module" | "user", name: string, file: sharp.Sharp): Promise<void> {

app/api/(utils)/webhooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const onModuleCreated = async (module: RelationalModule<"user">) => {
3333

3434
if (module.summary) embed.addFields({ name: "Summary", value: module.summary });
3535

36-
if (module.hasImage) {
36+
if (module.has_image) {
3737
embed.setImage(`${process.env.NEXT_PUBLIC_WEB_ROOT}/api/modules/${module.name}/image`);
3838
}
3939

app/api/account/modify/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const POST = route(async (req: NextRequest) => {
5757
where: { id: user.id },
5858
data: {
5959
name: username,
60-
hasImage: !!image,
60+
has_image: !!image,
6161
last_name_change_time: new Date(),
6262
},
6363
});

app/api/account/new/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const PUT = route(async (req: NextRequest) => {
4949
email,
5050
email_verified: false,
5151
password: bcrypt.hashSync(password, bcrypt.genSaltSync()),
52-
hasImage: !!image,
52+
has_image: !!image,
5353
},
5454
});
5555

app/api/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface PublicModule {
88
name: string;
99
summary: string | null;
1010
description: string | null;
11-
hasImage: boolean;
11+
has_image: boolean;
1212
downloads: number;
1313
hidden?: boolean;
1414
tags?: string[];
@@ -38,7 +38,7 @@ export interface PublicNotification {
3838
export interface PublicUser {
3939
id: string;
4040
name: string;
41-
hasImage: boolean;
41+
has_image: boolean;
4242
rank: Rank;
4343
created_at: number;
4444
}
@@ -79,7 +79,7 @@ const makePrismaClient = () => {
7979
user_id: true,
8080
summary: true,
8181
description: true,
82-
hasImage: true,
82+
has_image: true,
8383
downloads: true,
8484
hidden: true,
8585
tags: true,
@@ -112,7 +112,7 @@ const makePrismaClient = () => {
112112
name: module.name,
113113
summary: module.summary,
114114
description: module.description,
115-
hasImage: module.hasImage,
115+
has_image: module.has_image,
116116
downloads: module.downloads,
117117
hidden: module.hidden || undefined,
118118
tags: module.tags && module.tags.length > 0 ? module.tags.split(",") : undefined,
@@ -125,12 +125,12 @@ const makePrismaClient = () => {
125125
},
126126
imageDataUrl: {
127127
needs: {
128-
hasImage: true,
128+
has_image: true,
129129
name: true,
130130
},
131131
compute(module) {
132132
return async (): Promise<string | undefined> => {
133-
if (!module.hasImage) return undefined;
133+
if (!module.has_image) return undefined;
134134
return storage().getImageUrl("module", module.name);
135135
};
136136
},
@@ -185,15 +185,15 @@ const makePrismaClient = () => {
185185
needs: {
186186
id: true,
187187
name: true,
188-
hasImage: true,
188+
has_image: true,
189189
rank: true,
190190
created_at: true,
191191
},
192192
compute(user) {
193193
return (): PublicUser => ({
194194
id: user.id,
195195
name: user.name,
196-
hasImage: user.hasImage,
196+
has_image: user.has_image,
197197
rank: user.rank,
198198
created_at: user.created_at.getTime(),
199199
});
@@ -203,7 +203,7 @@ const makePrismaClient = () => {
203203
needs: {
204204
id: true,
205205
name: true,
206-
hasImage: true,
206+
has_image: true,
207207
rank: true,
208208
created_at: true,
209209

@@ -215,7 +215,7 @@ const makePrismaClient = () => {
215215
return async (): Promise<AuthenticatedUser> => ({
216216
id: user.id,
217217
name: user.name,
218-
hasImage: user.hasImage,
218+
has_image: user.has_image,
219219
rank: user.rank,
220220
created_at: user.created_at.getTime(),
221221

app/api/modules/[nameOrId]/image/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const GET = route(async (_req: NextRequest, { params }: SlugProps<"nameOr
77
const module = await modules.getOne(params.nameOrId);
88
if (!module) throw new NotFoundError("Module not found");
99

10-
if (module.hasImage) {
10+
if (module.has_image) {
1111
return Response.redirect(storage().getImageUrl("module", module.name));
1212
}
1313

app/api/modules/[nameOrId]/releases/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ async function saveZipFile(
130130
metadata.name = module.name;
131131
metadata.version = release.release_version;
132132
metadata.tags = module.tags ? module.tags.split(",") : undefined;
133-
metadata.pictureLink = module.hasImage
133+
metadata.pictureLink = module.has_image
134134
? await storage().getImageUrl("module", module.name)
135135
: undefined;
136136
metadata.creator = module.user.name;

app/api/modules/[nameOrId]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const PATCH = route(async (req: NextRequest, { params }: SlugProps<"nameO
8282
data: {
8383
summary,
8484
description,
85-
hasImage: !!image,
85+
has_image: !!image,
8686
hidden,
8787
tags,
8888
},

app/api/modules/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const PUT = route(async (req: NextRequest) => {
9393
name,
9494
summary,
9595
description,
96-
hasImage: !!image,
96+
has_image: !!image,
9797
tags: tags.join(","),
9898
hidden: hidden === "1" || hidden === "true",
9999
},

app/api/users/[nameOrId]/image/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const GET = route(async (_req: NextRequest, { params }: SlugProps<"nameOr
1111
});
1212
if (!user) return new Response("User not found", { status: 404 });
1313

14-
if (user.hasImage) {
14+
if (user.has_image) {
1515
return Response.redirect(storage().getImageUrl("user", user.name));
1616
}
1717

0 commit comments

Comments
 (0)