Merge branch 'Huskydog9988-more-ui-work' into develop
This commit is contained in:
@@ -3,9 +3,7 @@ import prisma from "~/server/internal/db/database";
|
||||
import objectHandler from "~/server/internal/objects";
|
||||
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const allowed = await aclManager.allowSystemACL(h3, [
|
||||
"game:image:delete",
|
||||
]);
|
||||
const allowed = await aclManager.allowSystemACL(h3, ["game:image:delete"]);
|
||||
if (!allowed) throw createError({ statusCode: 403 });
|
||||
|
||||
const body = await readBody(h3);
|
||||
@@ -37,8 +35,8 @@ export default defineEventHandler(async (h3) => {
|
||||
throw createError({ statusCode: 400, statusMessage: "Image not found" });
|
||||
|
||||
game.mImageLibrary.splice(imageIndex, 1);
|
||||
await objectHandler.delete(imageId);
|
||||
|
||||
await objectHandler.deleteAsSystem(imageId);
|
||||
|
||||
if (game.mBannerId === imageId) {
|
||||
game.mBannerId = game.mImageLibrary[0];
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import * as jdenticon from "jdenticon";
|
||||
import objectHandler from "~/server/internal/objects";
|
||||
import { type } from "arktype";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { writeNonLiteralDefaultMessage } from "arktype/internal/parser/shift/operator/default.ts";
|
||||
|
||||
const userValidator = type({
|
||||
username: "string >= 5",
|
||||
@@ -64,7 +63,7 @@ export default defineEventHandler(async (h3) => {
|
||||
profilePictureId,
|
||||
async () => jdenticon.toPng(user.username, 256),
|
||||
{},
|
||||
[`internal:read`, `${userId}:write`]
|
||||
[`internal:read`, `${userId}:read`]
|
||||
);
|
||||
const [linkMec] = await prisma.$transaction([
|
||||
prisma.linkedAuthMec.create({
|
||||
|
||||
@@ -11,6 +11,21 @@ export default defineEventHandler(async (h3) => {
|
||||
if (!object)
|
||||
throw createError({ statusCode: 404, statusMessage: "Object not found" });
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
|
||||
const etagRequestValue = h3.headers.get("If-None-Match");
|
||||
const etagActualValue = await objectHandler.fetchHash(id);
|
||||
if (
|
||||
etagRequestValue &&
|
||||
etagActualValue &&
|
||||
etagActualValue === etagRequestValue
|
||||
) {
|
||||
// would compare if etag is valid, but objects should never change
|
||||
setResponseStatus(h3, 304);
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: fix undefined etagValue
|
||||
setHeader(h3, "ETag", etagActualValue ?? "");
|
||||
setHeader(h3, "Content-Type", object.mime);
|
||||
setHeader(
|
||||
h3,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import aclManager from "~/server/internal/acls";
|
||||
import objectHandler from "~/server/internal/objects";
|
||||
|
||||
// this request method is purely used by the browser to check if etag values are still valid
|
||||
export default defineEventHandler(async (h3) => {
|
||||
const id = getRouterParam(h3, "id");
|
||||
if (!id) throw createError({ statusCode: 400, statusMessage: "Invalid ID" });
|
||||
|
||||
const userId = await aclManager.getUserIdACL(h3, ["object:read"]);
|
||||
|
||||
const object = await objectHandler.fetchWithPermissions(id, userId);
|
||||
if (!object)
|
||||
throw createError({ statusCode: 404, statusMessage: "Object not found" });
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
|
||||
const etagRequestValue = h3.headers.get("If-None-Match");
|
||||
const etagActualValue = await objectHandler.fetchHash(id);
|
||||
if (etagRequestValue !== null && etagActualValue === etagRequestValue) {
|
||||
// would compare if etag is valid, but objects should never change
|
||||
setResponseStatus(h3, 304);
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
Reference in New Issue
Block a user