Skip to content

Commit 3655a90

Browse files
committed
check author
1 parent d8625a4 commit 3655a90

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

app/api/v1/projects/route.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,28 @@ export async function GET(request: Request) {
2323
const type = searchParams.get("type");
2424
const q = searchParams.get("q");
2525
const sort = searchParams.get("sort") || "downloads";
26+
const author = searchParams.get("author");
2627

2728
let conditions = [eq(projects.status, "public")];
29+
30+
// 自分自身のリクエストかチェックするため、APIキーがあるか確認する
31+
let isMine = false;
32+
if (author) {
33+
const auth = await validateApiKey(request);
34+
if (auth.valid && auth.userId) {
35+
const [u] = await db.select().from(userProfiles).where(eq(userProfiles.username, author)).limit(1);
36+
if (u && u.userId === auth.userId) {
37+
isMine = true;
38+
}
39+
}
40+
41+
if (isMine) {
42+
// 自分の場合は、status=public の条件を外し、全て表示するか、削除済み以外とする
43+
conditions = [];
44+
}
45+
conditions.push(eq(userProfiles.username, author));
46+
}
47+
2848
if (type === "mod" || type === "plugin") {
2949
conditions.push(eq(projects.type, type as "mod" | "plugin"));
3050
}

0 commit comments

Comments
 (0)