fix: etags and other

remove sanitize-filename because IDs are internally generated
remove pulse animation on NO GAME cards
add migration
refactors to be inline with other stuff
This commit is contained in:
DecDuck
2025-04-14 10:52:12 +10:00
parent f384492ed2
commit c2bb835b0f
12 changed files with 85 additions and 125 deletions
+34 -58
View File
@@ -120,6 +120,32 @@ export class ObjectHandler {
});
}
// We only need one permission, so find instead of filter is faster
private hasAnyPermissions(permissions: string[], userId?: string) {
return !!permissions.find((e) => {
if (userId !== undefined && e.startsWith(userId)) return true;
if (userId !== undefined && e.startsWith("internal")) return true;
if (e.startsWith("anonymous")) return true;
return false;
});
}
private fetchPermissions(permissions: string[], userId?: string) {
return (
permissions
.filter((e) => {
if (userId !== undefined && e.startsWith(userId)) return true;
if (userId !== undefined && e.startsWith("internal")) return true;
if (e.startsWith("anonymous")) return true;
return false;
})
// Strip IDs from permissions
.map((e) => e.split(":").at(1))
// Map to priority according to array
.map((e) => ObjectPermissionPriority.findIndex((c) => c === e))
);
}
/**
* Fetches object, but also checks if user has perms to access it
* @param id object id
@@ -130,18 +156,7 @@ export class ObjectHandler {
const metadata = await this.backend.fetchMetadata(id);
if (!metadata) return;
// We only need one permission, so find instead of filter is faster
const myPermissions = metadata.permissions.find((e) => {
if (userId !== undefined && e.startsWith(userId)) return true;
if (userId !== undefined && e.startsWith("internal")) return true;
if (e.startsWith("anonymous")) return true;
return false;
});
if (!myPermissions) {
// We do not have access to this object
return;
}
if (!this.hasAnyPermissions(metadata.permissions, userId)) return;
// Because any permission can be read or up, we automatically know we can read this object
// So just straight return the object
@@ -155,30 +170,11 @@ export class ObjectHandler {
}
/**
* Fetch object hash, but also checks if user has perms to access it
* Fetch object hash. Permissions check should be done on read
* @param id object id
* @param userId user to check, or act as anon user
* @returns
*/
async fetchHashWithWithPermissions(id: ObjectReference, userId?: string) {
const metadata = await this.backend.fetchMetadata(id);
if (!metadata) return;
// We only need one permission, so find instead of filter is faster
const myPermissions = metadata.permissions.find((e) => {
if (userId !== undefined && e.startsWith(userId)) return true;
if (userId !== undefined && e.startsWith("internal")) return true;
if (e.startsWith("anonymous")) return true;
return false;
});
if (!myPermissions) {
// We do not have access to this object
return;
}
// Because any permission can be read or up, we automatically know we can read this object
// So just straight return the object
async fetchHash(id: ObjectReference) {
return await this.backend.fetchHash(id);
}
@@ -202,21 +198,11 @@ export class ObjectHandler {
const metadata = await this.backend.fetchMetadata(id);
if (!metadata) return false;
const myPermissions = metadata.permissions
.filter((e) => {
if (userId !== undefined && e.startsWith(userId)) return true;
if (userId !== undefined && e.startsWith("internal")) return true;
if (e.startsWith("anonymous")) return true;
return false;
})
// Strip IDs from permissions
.map((e) => e.split(":").at(1))
// Map to priority according to array
.map((e) => ObjectPermissionPriority.findIndex((c) => c === e));
const permissions = this.fetchPermissions(metadata.permissions, userId);
const requiredPermissionIndex = 1;
const hasPermission =
myPermissions.find((e) => e >= requiredPermissionIndex) != undefined;
permissions.find((e) => e >= requiredPermissionIndex) != undefined;
if (!hasPermission) return false;
@@ -237,21 +223,11 @@ export class ObjectHandler {
const metadata = await this.backend.fetchMetadata(id);
if (!metadata) return false;
const myPermissions = metadata.permissions
.filter((e) => {
if (userId !== undefined && e.startsWith(userId)) return true;
if (userId !== undefined && e.startsWith("internal")) return true;
if (e.startsWith("anonymous")) return true;
return false;
})
// Strip IDs from permissions
.map((e) => e.split(":").at(1))
// Map to priority according to array
.map((e) => ObjectPermissionPriority.findIndex((c) => c === e));
const permissions = this.fetchPermissions(metadata.permissions, userId);
const requiredPermissionIndex = 2;
const hasPermission =
myPermissions.find((e) => e >= requiredPermissionIndex) != undefined;
permissions.find((e) => e >= requiredPermissionIndex) != undefined;
if (!hasPermission) return false;
@@ -264,7 +240,7 @@ export class ObjectHandler {
* @param id
* @returns
*/
async deleteAsServer(id: ObjectReference) {
async deleteAsSystem(id: ObjectReference) {
return await this.backend.delete(id);
}
}