forked from FoundKeyGang/FoundKey
server: change JSON.parse/stringify to structuredClone
structuredClone is more typesafe than using JSON.parse and JSON.stringify. Now that Node 18.x is the new baseline, this should be safe to use now. See https://developer.mozilla.org/en-US/docs/Web/API/structuredClone for details.
This commit is contained in:
parent
a9d3cae511
commit
78717e85d3
3 changed files with 3 additions and 7 deletions
|
@ -27,9 +27,7 @@ export const DriveFileRepository = db.getRepository(DriveFile).extend({
|
|||
|
||||
getPublicProperties(file: DriveFile): DriveFile['properties'] {
|
||||
if (file.properties.orientation != null) {
|
||||
// TODO
|
||||
//const properties = structuredClone(file.properties);
|
||||
const properties = JSON.parse(JSON.stringify(file.properties));
|
||||
const properties = structuredClone(file.properties);
|
||||
if (file.properties.orientation >= 5) {
|
||||
[properties.width, properties.height] = [properties.height, properties.width];
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import manifest from './manifest.json' assert { type: 'json' };
|
|||
export const manifestHandler = async (ctx: Koa.Context): Promise<void> => {
|
||||
// TODO
|
||||
//const res = structuredClone(manifest);
|
||||
const res = JSON.parse(JSON.stringify(manifest));
|
||||
const res = structuredClone(manifest);
|
||||
|
||||
const instance = await fetchMeta(true);
|
||||
|
||||
|
|
|
@ -96,9 +96,7 @@ export async function deliverToRelays(user: { id: User['id']; host: null; }, act
|
|||
const relays = await relaysCache.fetch('');
|
||||
if (relays == null || relays.length === 0) return;
|
||||
|
||||
// TODO
|
||||
//const copy = structuredClone(activity);
|
||||
const copy = JSON.parse(JSON.stringify(activity));
|
||||
const copy = structuredClone(activity);
|
||||
if (!copy.to) copy.to = ['https://www.w3.org/ns/activitystreams#Public'];
|
||||
|
||||
const signed = await attachLdSignature(copy, user);
|
||||
|
|
Loading…
Reference in a new issue