server: change JSON.parse/stringify to structuredClone
Some checks failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/build Pipeline failed
ci/woodpecker/push/lint-foundkey-js Pipeline failed
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/test Pipeline failed

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:
Norm 2022-12-13 16:45:04 -05:00
parent a9d3cae511
commit 78717e85d3
Signed by: norm
GPG key ID: 7123E30E441E80DE
3 changed files with 3 additions and 7 deletions

View file

@ -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];
}

View file

@ -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);

View file

@ -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);