From a2f55fc6f11f90a14d117e5da391a61e4b10afc7 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Sat, 4 Mar 2023 11:03:07 -0800 Subject: [PATCH] Add option in API to normalize file extension --- .../graphql/resolvers/ClassicSkinResolver.ts | 8 +++++++ .../graphql/resolvers/CommonSkinResolver.ts | 4 +--- .../graphql/resolvers/ModernSkinResolver.ts | 8 +++++++ .../skin-database/api/graphql/schema.graphql | 24 ++++++++++++++++--- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/packages/skin-database/api/graphql/resolvers/ClassicSkinResolver.ts b/packages/skin-database/api/graphql/resolvers/ClassicSkinResolver.ts index 59252b7e..85420d46 100644 --- a/packages/skin-database/api/graphql/resolvers/ClassicSkinResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/ClassicSkinResolver.ts @@ -1,6 +1,7 @@ import CommonSkinResolver from "./CommonSkinResolver"; import { NodeResolver, toId } from "./NodeResolver"; import ReviewResolver from "./ReviewResolver"; +import path from "path"; export default class ClassicSkinResolver extends CommonSkinResolver @@ -10,6 +11,13 @@ export default class ClassicSkinResolver async id() { return toId(this.__typename, this.md5()); } + async filename(normalize_extension = false) { + const filename = await this._model.getFileName(); + if (normalize_extension) { + return path.parse(filename).name + ".wsz"; + } + return filename; + } museum_url() { return this._model.getMuseumUrl(); } diff --git a/packages/skin-database/api/graphql/resolvers/CommonSkinResolver.ts b/packages/skin-database/api/graphql/resolvers/CommonSkinResolver.ts index 91d71b0b..1bd41584 100644 --- a/packages/skin-database/api/graphql/resolvers/CommonSkinResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/CommonSkinResolver.ts @@ -12,9 +12,7 @@ export default class CommonSkinResolver { md5() { return this._model.getMd5(); } - filename() { - return this._model.getFileName(); - } + download_url() { return this._model.getSkinUrl(); } diff --git a/packages/skin-database/api/graphql/resolvers/ModernSkinResolver.ts b/packages/skin-database/api/graphql/resolvers/ModernSkinResolver.ts index 5e2c13fd..e05e24aa 100644 --- a/packages/skin-database/api/graphql/resolvers/ModernSkinResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/ModernSkinResolver.ts @@ -1,6 +1,7 @@ import SkinModel from "../../../data/SkinModel"; import CommonSkinResolver from "./CommonSkinResolver"; import { NodeResolver, toId } from "./NodeResolver"; +import path from "path"; export default class ModernSkinResolver extends CommonSkinResolver @@ -11,4 +12,11 @@ export default class ModernSkinResolver async id() { return toId(this.__typename, this.md5()); } + async filename(normalize_extension = false) { + const filename = await this._model.getFileName(); + if (normalize_extension) { + return path.parse(filename).name + ".wal"; + } + return filename; + } } diff --git a/packages/skin-database/api/graphql/schema.graphql b/packages/skin-database/api/graphql/schema.graphql index 5cfb4d8c..446b5ad6 100644 --- a/packages/skin-database/api/graphql/schema.graphql +++ b/packages/skin-database/api/graphql/schema.graphql @@ -32,7 +32,13 @@ interface Skin { Filename of skin when uploaded to the Museum. Note: In some cases a skin has been uploaded under multiple names. Here we just pick one. """ - filename: String + filename( + """ + If true, the the correct file extension (.wsz or .wal) will be . + Otherwise, the original user-uploaded file extension will be used. + """ + normalize_extension: Boolean = false + ): String """ Has the skin been tweeted? @@ -97,7 +103,13 @@ type ModernSkin implements Skin & Node { Filename of skin when uploaded to the Museum. Note: In some cases a skin has been uploaded under multiple names. Here we just pick one. """ - filename: String + filename( + """ + If true, the the correct file extension (.wsz or .wal) will be . + Otherwise, the original user-uploaded file extension will be used. + """ + normalize_extension: Boolean = false + ): String """ Has the skin been tweeted? @@ -174,7 +186,13 @@ type ClassicSkin implements Skin & Node { Filename of skin when uploaded to the Museum. Note: In some cases a skin has been uploaded under multiple names. Here we just pick one. """ - filename: String + filename( + """ + If true, the the correct file extension (.wsz or .wal) will be . + Otherwise, the original user-uploaded file extension will be used. + """ + normalize_extension: Boolean = false + ): String """ Text of the readme file extracted from the skin