-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
051c827
commit e8a2a7e
Showing
23 changed files
with
260 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default defineEventHandler(() => { | ||
return { | ||
hello: "world", | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { verifyPrimitiveMetadata } from "@shared/verify" | ||
import { UserTable } from "#/database/user" | ||
|
||
export default defineEventHandler(async (event) => { | ||
try { | ||
const { id } = event.context.user | ||
const db = useDatabase() | ||
if (!db) throw new Error("Not found database") | ||
const userTable = new UserTable(db) | ||
if (event.method === "GET") { | ||
const { data, updated } = await userTable.getData(id) | ||
return { | ||
data: data ? JSON.parse(data) : undefined, | ||
updatedTime: updated, | ||
} | ||
} else if (event.method === "POST") { | ||
const body = await readBody(event) | ||
verifyPrimitiveMetadata(body) | ||
const { updatedTime, data } = body | ||
await userTable.setData(id, JSON.stringify(data), updatedTime) | ||
return { | ||
success: true, | ||
updatedTime, | ||
} | ||
} | ||
} catch (e) { | ||
logger.error(e) | ||
throw createError({ | ||
statusCode: 500, | ||
message: e instanceof Error ? e.message : "Internal Server Error", | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import z from "zod" | ||
|
||
export function verifyPrimitiveMetadata(target: any) { | ||
return z.object({ | ||
data: z.record(z.string(), z.array(z.string())), | ||
updatedTime: z.number(), | ||
}).parse(target) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.