From 1c8b4e0478debb28cb6944e4a23e9409116d4a33 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Fri, 1 Mar 2024 23:26:06 -0800 Subject: [PATCH] Upgrade grats --- packages/skin-database/.prettierignore | 1 + .../api/__tests__/graphql.test.ts | 2 +- packages/skin-database/api/app.ts | 7 +- .../api/graphql/ModernSkinsConnection.ts | 6 +- .../api/graphql/SkinsConnection.ts | 14 +- .../api/graphql/TweetsConnection.ts | 6 +- .../api/graphql/grats-schema.graphql | 497 ------- packages/skin-database/api/graphql/index.ts | 11 +- .../api/graphql/resolvers/MutationResolver.ts | 219 +-- .../api/graphql/resolvers/ReviewResolver.ts | 3 +- .../api/graphql/resolvers/RootResolver.ts | 417 +++--- .../api/graphql/resolvers/UserResolver.ts | 4 +- .../skin-database/api/graphql/schema.graphql | 715 +++++----- packages/skin-database/api/graphql/schema.ts | 1249 +++++++++++++++++ packages/skin-database/package.json | 10 +- packages/skin-database/s3.js | 1 - packages/skin-database/tsconfig.json | 5 +- yarn.lock | 40 +- 18 files changed, 1997 insertions(+), 1210 deletions(-) create mode 100644 packages/skin-database/.prettierignore delete mode 100644 packages/skin-database/api/graphql/grats-schema.graphql create mode 100644 packages/skin-database/api/graphql/schema.ts diff --git a/packages/skin-database/.prettierignore b/packages/skin-database/.prettierignore new file mode 100644 index 00000000..804359d8 --- /dev/null +++ b/packages/skin-database/.prettierignore @@ -0,0 +1 @@ +api/graphql/schema.ts \ No newline at end of file diff --git a/packages/skin-database/api/__tests__/graphql.test.ts b/packages/skin-database/api/__tests__/graphql.test.ts index c2903e27..75692f8d 100644 --- a/packages/skin-database/api/__tests__/graphql.test.ts +++ b/packages/skin-database/api/__tests__/graphql.test.ts @@ -231,7 +231,7 @@ describe("Query.skins", () => { }); // TODO: Upgrade Grats -test.skip("Query.fetch_skin_by_md5 (debug data)", async () => { +test("Query.fetch_skin_by_md5 (debug data)", async () => { const { data } = await graphQLRequest( gql` query MyQuery($md5: String!) { diff --git a/packages/skin-database/api/app.ts b/packages/skin-database/api/app.ts index 8e8177f6..7449ce92 100644 --- a/packages/skin-database/api/app.ts +++ b/packages/skin-database/api/app.ts @@ -21,7 +21,12 @@ export type ApiAction = | { type: "CLASSIC_SKIN_UPLOADED"; md5: string } | { type: "MODERN_SKIN_UPLOADED"; md5: string } | { type: "SKIN_UPLOAD_ERROR"; uploadId: string; message: string } - | { type: "GOT_FEEDBACK"; message: string; email?: string; url?: string } + | { + type: "GOT_FEEDBACK"; + message: string; + email?: string | null; + url?: string | null; + } | { type: "SYNCED_TO_ARCHIVE"; successes: number; errors: number } | { type: "STARTED_SYNC_TO_ARCHIVE"; count: number } | { diff --git a/packages/skin-database/api/graphql/ModernSkinsConnection.ts b/packages/skin-database/api/graphql/ModernSkinsConnection.ts index 22cd3878..bfd0cc63 100644 --- a/packages/skin-database/api/graphql/ModernSkinsConnection.ts +++ b/packages/skin-database/api/graphql/ModernSkinsConnection.ts @@ -2,6 +2,7 @@ import { Int } from "grats"; import SkinModel from "../../data/SkinModel"; import { knex } from "../../db"; import ModernSkinResolver from "./resolvers/ModernSkinResolver"; +import { Ctx } from "."; /** * A collection of "modern" Winamp skins @@ -29,7 +30,10 @@ export default class ModernSkinsConnection { /** * The list of skins * @gqlField */ - async nodes(_args: never, ctx): Promise> { + async nodes( + _args: unknown, + { ctx }: Ctx + ): Promise> { const skins = await this._getQuery() .select() .limit(this._first) diff --git a/packages/skin-database/api/graphql/SkinsConnection.ts b/packages/skin-database/api/graphql/SkinsConnection.ts index 10658b4d..b574338d 100644 --- a/packages/skin-database/api/graphql/SkinsConnection.ts +++ b/packages/skin-database/api/graphql/SkinsConnection.ts @@ -5,6 +5,7 @@ import SkinResolver from "./resolvers/SkinResolver"; import LRU from "lru-cache"; import { Int } from "grats"; import { ISkin } from "./resolvers/CommonSkinResolver"; +import { Ctx } from "."; const options = { max: 100, @@ -43,9 +44,14 @@ async function getSkinMuseumPageFromCache(first: number, offset: number) { export default class SkinsConnection { _first: number; _offset: number; - _sort?: string; - _filter?: string; - constructor(first: number, offset: number, sort?: string, filter?: string) { + _sort?: string | null; + _filter?: string | null; + constructor( + first: number, + offset: number, + sort?: string | null, + filter?: string | null + ) { this._first = first; this._offset = offset; this._filter = filter; @@ -96,7 +102,7 @@ export default class SkinsConnection { * The list of skins * @gqlField */ - async nodes(args: never, ctx): Promise> { + async nodes(args: unknown, { ctx }: Ctx): Promise> { if (this._sort === "MUSEUM") { if (this._filter) { throw new Error( diff --git a/packages/skin-database/api/graphql/TweetsConnection.ts b/packages/skin-database/api/graphql/TweetsConnection.ts index cc2ff0ae..2145a865 100644 --- a/packages/skin-database/api/graphql/TweetsConnection.ts +++ b/packages/skin-database/api/graphql/TweetsConnection.ts @@ -12,8 +12,8 @@ export type TweetsSortOption = "LIKES" | "RETWEETS"; export default class TweetsConnection { _first: number; _offset: number; - _sort?: TweetsSortOption; - constructor(first: number, offset: number, sort?: TweetsSortOption) { + _sort?: TweetsSortOption | null; + constructor(first: number, offset: number, sort?: TweetsSortOption | null) { this._first = first; this._offset = offset; this._sort = sort; @@ -43,7 +43,7 @@ export default class TweetsConnection { * The list of tweets * @gqlField */ - async nodes(args: never, ctx): Promise> { + async nodes(): Promise> { return this._getQuery().select().limit(this._first).offset(this._offset); } } diff --git a/packages/skin-database/api/graphql/grats-schema.graphql b/packages/skin-database/api/graphql/grats-schema.graphql deleted file mode 100644 index beaf1d52..00000000 --- a/packages/skin-database/api/graphql/grats-schema.graphql +++ /dev/null @@ -1,497 +0,0 @@ -schema { - query: Query - mutation: Mutation -} - -directive @exported(filename: String!, functionName: String!) on FIELD_DEFINITION - -directive @methodName(name: String!) on FIELD_DEFINITION - -"""A file found within a Winamp Skin's .wsz archive""" -type ArchiveFile { - """ - The date on the file inside the archive. Given in simplified extended ISO - format (ISO 8601). - """ - date: String - """The md5 hash of the file within the archive""" - file_md5: String - """Filename of the file within the archive""" - filename: String - """Is the file a directory?""" - is_directory: Boolean - """ - The uncompressed size of the file in bytes. - - **Note:** Will be `null` for directories - """ - size: Int - """The skin in which this file was found""" - skin: Skin - """The content of the file, if it's a text file""" - text_content: String - """ - A URL to download the file. **Note:** This is powered by a little - serverless Cloudflare function which tries to exctact the file on the fly. - It may not work for all files. - """ - url: String -} - -"""A classic Winamp skin""" -type ClassicSkin implements Node & Skin { - """List of files contained within the skin's .wsz archive""" - archive_files: [ArchiveFile] - """String representation (rgb usually) of the skin's average color""" - average_color: String - """URL to download the skin""" - download_url: String - """ - 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( - """ - 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 - """Does the skin include sprite sheets for the media library?""" - has_media_library: Boolean - """GraphQL ID of the skin""" - id: ID! - """The skin's "item" at archive.org""" - internet_archive_item: InternetArchiveItem - """ - The date on which this skin was last updated in the Algolia search index. - Given in simplified extended ISO format (ISO 8601). - """ - last_algolia_index_update_date: String - """MD5 hash of the skin's file""" - md5: String - """URL of the skin on the Winamp Skin Museum""" - museum_url: String - """Has the skin been flagged as "not safe for wrok"?""" - nsfw: Boolean - """Text of the readme file extracted from the skin""" - readme_text: String - """ - Times that the skin has been reviewed either on the Museum's Tinder-style - reivew page, or via the Discord bot. - """ - reviews: [Review] - """URL of a screenshot of the skin""" - screenshot_url: String - """The number of transparent pixels rendered by the skin.""" - transparent_pixels: Int - """Has the skin been tweeted?""" - tweeted: Boolean - """List of @winampskins tweets that mentioned the skin.""" - tweets: [Tweet] - """URL of webamp.org with the skin loaded""" - webamp_url: String -} - -"""Statistics about the contents of the Museum's database.""" -type DatabaseStatistics { - """ - The number of skins that have been approved for tweeting. This includes both - tweeted and untweeted skins. - - **Note:** Skins can be both approved and rejected by different users. - """ - approved_skins_count: Int - """ - The number of skins that have been marked as NSFW. - - **Note:** Skins can be approved and rejected by different users. - **Note:** Generally skins that have been marked NSFW are also marked as rejected. - """ - nsfw_skins_count: Int - """ - The number of skins that have been rejected for tweeting. - - **Note:** Skins can be both approved and rejected by different users. - **Note:** Generally skins that have been marked NSFW are also marked as rejected. - """ - rejected_skins_count: Int - """ - The number of skins that have been approved for tweeting, but not yet tweeted. - """ - tweetable_skins_count: Int - """ - The number of skins in the Museum that have been tweeted by @winampskins - """ - tweeted_skins_count: Int - """The total number of classic skins in the Museum's database""" - unique_classic_skins_count: Int - """The number of skins that have never been reviewed.""" - unreviewed_skins_count: Int - """Skins uploads that have errored during processing.""" - uploads_in_error_state_count: Int - """ - Skins uplaods awaiting processing. This can happen when there are a large - number of skin uplaods at the same time, or when the skin uploading processing - pipeline gets stuck. - """ - uploads_pending_processing_count: Int - """ - Number of skins that have been uploaded to the Museum via the web interface. - """ - web_uploads_count: Int -} - -type InternetArchiveItem { - """The Internet Archive's unique identifier for this item""" - identifier: String - """ - The date and time that we last scraped this item's metadata. - **Note:** This field is temporary and will be removed in the future. - The date format is just what we get from the database, and it's ambiguous. - """ - last_metadata_scrape_date_UNSTABLE: String - """URL to get the Internet Archive's metadata for this item in JSON form.""" - metadata_url: String - """ - Our cached version of the metadata avaliable at \`metadata_url\` (above) - """ - raw_metadata_json: String - """The skin that this item contains""" - skin: Skin - """The URL where this item can be viewed on the Internet Archive""" - url: String -} - -""" -A "modern" Winamp skin. These skins use the `.wal` file extension and are free-form. - -Most functionality in the Winamp Skin Museum is centered around "classic" skins, -which are currently called just `Skin` in this schema. -""" -type ModernSkin implements Node & Skin { - """List of files contained within the skin's .wsz archive""" - archive_files: [ArchiveFile] - average_color: String @deprecated(reason: "Needed for migration") - """URL to download the skin""" - download_url: String - """ - 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( - """ - 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 - """GraphQL ID of the skin""" - id: ID! - """The skin's "item" at archive.org""" - internet_archive_item: InternetArchiveItem - """MD5 hash of the skin's file""" - md5: String - museum_url: String @deprecated(reason: "Needed for migration") - nsfw: Boolean @deprecated(reason: "Needed for migration") - readme_text: String @deprecated(reason: "Needed for migration") - """ - Times that the skin has been reviewed either on the Museum's Tinder-style - reivew page, or via the Discord bot. - """ - reviews: [Review] - screenshot_url: String @deprecated(reason: "Needed for migration") - """Has the skin been tweeted?""" - tweeted: Boolean - """List of @winampskins tweets that mentioned the skin.""" - tweets: [Tweet] - webamp_url: String @deprecated(reason: "Needed for migration") -} - -"""A collection of "modern" Winamp skins""" -type ModernSkinsConnection { - """The total number of skins matching the filter""" - count: Int - """The list of skins""" - nodes: [ModernSkin] -} - -type Mutation { - """ - Approve skin for tweeting - - **Note:** Requires being logged in - """ - approve_skin(md5: String!): Boolean - """ - Mark a skin as NSFW - - **Note:** Requires being logged in - """ - mark_skin_nsfw(md5: String!): Boolean - """ - Reject skin for tweeting - - **Note:** Requires being logged in - """ - reject_skin(md5: String!): Boolean - """ - Request that an admin check if this skin is NSFW. - Unlike other review mutaiton endpoints, this one does not require being logged - in. - """ - request_nsfw_review_for_skin(md5: String!): Boolean - """ - Send a message to the admin of the site. Currently this appears in Discord. - """ - send_feedback(email: String, message: String!, url: String): Boolean - """Mutations for the upload flow""" - upload: UploadMutations -} - -""" -A globally unique object. The `id` here is intended only for use within -GraphQL. -https://graphql.org/learn/global-object-identification/ -""" -interface Node { - id: ID! -} - -type Query { - """ - Fetch archive file by it's MD5 hash - - Get information about a file found within a skin's wsz/wal/zip archive. - """ - fetch_archive_file_by_md5(md5: String!): ArchiveFile - """ - Get an archive.org item by its identifier. You can find this in the URL: - - https://archive.org/details// - """ - fetch_internet_archive_item_by_identifier(identifier: String!): InternetArchiveItem - """Get a skin by its MD5 hash""" - fetch_skin_by_md5(md5: String!): Skin - """Get a tweet by its URL""" - fetch_tweet_by_url(url: String!): Tweet - """The currently authenticated user, if any.""" - me: User - """All modern skins in the database""" - modern_skins(first: Int = 10, offset: Int = 0): ModernSkinsConnection - """ - Get a globally unique object by its ID. - - https://graphql.org/learn/global-object-identification/ - """ - node(id: ID!): Node - """ - Search the database using the Algolia search index used by the Museum. - - Useful for locating a particular skin. - """ - search_skins(first: Int = 10, offset: Int = 0, query: String!): [Skin] - """A random skin that needs to be reviewed""" - skin_to_review: Skin - """ - All classic skins in the database - - **Note:** We don't currently support combining sorting and filtering. - """ - skins(filter: SkinsFilterOption, first: Int = 10, offset: Int = 0, sort: SkinsSortOption): SkinsConnection - """A namespace for statistics about the database""" - statistics: DatabaseStatistics - """Tweets tweeted by @winampskins""" - tweets(first: Int = 10, offset: Int = 0, sort: TweetsSortOption): TweetsConnection - """Get the status of a batch of uploads by ids""" - upload_statuses(ids: [String!]!): [SkinUpload] - """Get the status of a batch of uploads by md5s""" - upload_statuses_by_md5(md5s: [String!]!): [SkinUpload] @deprecated(reason: "Prefer `upload_statuses` instead, were we operate on ids.") -} - -"""The judgement made about a skin by a moderator""" -enum Rating { - APPROVED - NSFW - REJECTED -} - -""" -A review of a skin. Done either on the Museum's Tinder-style -reivew page, or via the Discord bot. -""" -type Review { - """The rating that the user gave the skin""" - rating: Rating - """ - The user who made the review (if known). **Note:** In the early days we didn't - track this, so many will be null. - """ - reviewer: String - """The skin that was reviewed""" - skin: Skin -} - -""" -A Winamp skin. Could be modern or classic. - -**Note**: At some point in the future, this might be renamed to `Skin`. -""" -interface Skin { - """List of files contained within the skin's .wsz archive""" - archive_files: [ArchiveFile] - average_color: String @deprecated(reason: "Needed for migration") - """URL to download the skin""" - download_url: String - """ - 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( - """ - 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 - """GraphQL ID of the skin""" - id: ID! - """The skin's "item" at archive.org""" - internet_archive_item: InternetArchiveItem - """MD5 hash of the skin's file""" - md5: String - museum_url: String @deprecated(reason: "Needed for migration") - nsfw: Boolean @deprecated(reason: "Needed for migration") - readme_text: String @deprecated(reason: "Needed for migration") - """ - Times that the skin has been reviewed either on the Museum's Tinder-style - reivew page, or via the Discord bot. - """ - reviews: [Review] - screenshot_url: String @deprecated(reason: "Needed for migration") - """Has the skin been tweeted?""" - tweeted: Boolean - """List of @winampskins tweets that mentioned the skin.""" - tweets: [Tweet] - webamp_url: String @deprecated(reason: "Needed for migration") -} - -"""Information about an attempt to upload a skin to the Museum.""" -type SkinUpload { - id: String - """ - Skin that was uploaded. **Note:** This is null if the skin has not yet been - fully processed. (status == ARCHIVED) - """ - skin: Skin - status: SkinUploadStatus - """Md5 hash given when requesting the upload URL.""" - upload_md5: String -} - -""" -The current status of a pending upload. - -**Note:** Expect more values here as we try to be more transparent about -the status of a pending uploads. -""" -enum SkinUploadStatus { - ARCHIVED - DELAYED - ERRORED - UPLOAD_REPORTED - URL_REQUESTED -} - -"""A collection of classic Winamp skins""" -type SkinsConnection { - """The total number of skins matching the filter""" - count: Int - """The list of skins""" - nodes: [Skin] -} - -enum SkinsFilterOption { - APPROVED - NSFW - REJECTED - TWEETED -} - -enum SkinsSortOption { - MUSEUM -} - -"""A tweet made by @winampskins mentioning a Winamp skin""" -type Tweet { - """ - Number of likes the tweet has received. Updated nightly. (Note: Recent likes on older tweets may not be reflected here) - """ - likes: Int - """ - Number of retweets the tweet has received. Updated nightly. (Note: Recent retweets on older tweets may not be reflected here) - """ - retweets: Int - """The skin featured in this Tweet""" - skin: Skin - """ - URL of the tweet. **Note:** Early on in the bot's life we just recorded - _which_ skins were tweeted, not any info about the actual tweet. This means we - don't always know the URL of the tweet. - """ - url: String -} - -"""A collection of tweets made by the @winampskins bot""" -type TweetsConnection { - """The total number of tweets""" - count: Int - """The list of tweets""" - nodes: [Tweet] -} - -enum TweetsSortOption { - LIKES - RETWEETS -} - -""" -Mutations for the upload flow - -1. The user finds the md5 hash of their local files. -2. (`get_upload_urls`) The user requests upload URLs for each of their files. -3. The server returns upload URLs for each of their files which are not already in the collection. -4. The user uploads each of their files to the URLs returned in step 3. -5. (`report_skin_uploaded`) The user notifies the server that they're done uploading. -6. (TODO) The user polls for the status of their uploads. -""" -type UploadMutations { - """ - Get a (possibly incompelte) list of UploadUrls for each of the files. If an - UploadUrl is not returned for a given hash, it means the file is already in - the collection. - """ - get_upload_urls(files: [UploadUrlRequest!]!): [UploadUrl] - """Notify the server that the user is done uploading.""" - report_skin_uploaded(id: String!, md5: String!): Boolean -} - -""" -A URL that the client can use to upload a skin to S3, and then notify the server -when they're done. -""" -type UploadUrl { - id: String - md5: String - url: String -} - -"""Input object used for a user to request an UploadUrl""" -input UploadUrlRequest { - filename: String! - md5: String! -} - -type User { - username: String -} \ No newline at end of file diff --git a/packages/skin-database/api/graphql/index.ts b/packages/skin-database/api/graphql/index.ts index 56f774e4..6f8b5314 100644 --- a/packages/skin-database/api/graphql/index.ts +++ b/packages/skin-database/api/graphql/index.ts @@ -1,14 +1,10 @@ import { RequestHandler, Router } from "express"; import { graphqlHTTP } from "express-graphql"; -import RootResolver from "./resolvers/RootResolver"; import DEFAULT_QUERY from "./defaultQuery"; -import { buildSchema } from "graphql"; -import fs from "fs"; -import path from "path"; +import { getSchema } from "./schema"; -const schemaPath = path.join(__dirname, "./schema.graphql"); -const schema = buildSchema(fs.readFileSync(schemaPath, "utf8")); +export type Ctx = Express.Request; const router = Router(); @@ -44,8 +40,7 @@ const extensions = ({ router.use( "/", graphqlHTTP({ - schema: schema, - rootValue: new RootResolver(), + schema: getSchema(), graphiql: { defaultQuery: DEFAULT_QUERY, }, diff --git a/packages/skin-database/api/graphql/resolvers/MutationResolver.ts b/packages/skin-database/api/graphql/resolvers/MutationResolver.ts index 85a8abb2..ccc04e09 100644 --- a/packages/skin-database/api/graphql/resolvers/MutationResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/MutationResolver.ts @@ -3,6 +3,7 @@ import SkinModel from "../../../data/SkinModel"; import * as S3 from "../../../s3"; import * as Skins from "../../../data/skins"; import { processUserUploads } from "../../processUserUploads"; +import { Ctx } from ".."; // We don't use a resolver here, just return the value directly. /** @@ -45,7 +46,7 @@ class UploadMutationResolver { */ async get_upload_urls( { files }: { files: UploadUrlRequest[] }, - { ctx } + { ctx }: Ctx ): Promise> { const missing: UploadUrl[] = []; await Parallel.each( @@ -69,7 +70,7 @@ class UploadMutationResolver { */ async report_skin_uploaded( { id, md5 }: { id: string; md5: string }, - req + req: Ctx ): Promise { // TODO: Validate md5 and id; await Skins.recordUserUploadComplete(md5, id); @@ -80,7 +81,7 @@ class UploadMutationResolver { } function requireAuthed(handler) { - return (args, req) => { + return (args, req: Ctx) => { if (!req.ctx.authed()) { throw new Error("You must be logged in to read this field."); } else { @@ -92,102 +93,120 @@ function requireAuthed(handler) { /** * * @gqlType Mutation */ -export default class MutationResolver { - /** - * Mutations for the upload flow - * @gqlField */ - async upload(): Promise { - return new UploadMutationResolver(); - } - /** - * Send a message to the admin of the site. Currently this appears in Discord. - * @gqlField */ - async send_feedback( - { message, email, url }: { message: string; email?: string; url?: string }, - req - ): Promise { - req.notify({ - type: "GOT_FEEDBACK", - url, - message, - email, - }); - return true; - } +type Mutation = unknown; - /** - * Reject skin for tweeting - * - * **Note:** Requires being logged in - * @gqlField */ - reject_skin(args: { md5: string }, req): Promise { - return this._reject_skin(args, req); - } - - _reject_skin = requireAuthed(async ({ md5 }, req) => { - req.log(`Rejecting skin with hash "${md5}"`); - const skin = await SkinModel.fromMd5Assert(req.ctx, md5); - if (skin == null) { - return false; - } - await Skins.reject(req.ctx, md5); - req.notify({ type: "REJECTED_SKIN", md5 }); - return true; - }); - - /** - * Approve skin for tweeting - * - * **Note:** Requires being logged in - * @gqlField */ - approve_skin(args: { md5: string }, req): Promise { - return this._approve_skin(args, req); - } - - _approve_skin = requireAuthed(async ({ md5 }, req) => { - req.log(`Approving skin with hash "${md5}"`); - const skin = await SkinModel.fromMd5(req.ctx, md5); - if (skin == null) { - return false; - } - await Skins.approve(req.ctx, md5); - req.notify({ type: "APPROVED_SKIN", md5 }); - return true; - }); - - /** - * Mark a skin as NSFW - * - * **Note:** Requires being logged in - * @gqlField */ - mark_skin_nsfw(args: { md5: string }, req): Promise { - return this._mark_skin_nsfw(args, req); - } - - _mark_skin_nsfw = requireAuthed(async ({ md5 }, req) => { - req.log(`Approving skin with hash "${md5}"`); - const skin = await SkinModel.fromMd5(req.ctx, md5); - if (skin == null) { - return false; - } - await Skins.markAsNSFW(req.ctx, md5); - req.notify({ type: "MARKED_SKIN_NSFW", md5 }); - return true; - }); - - /** - * Request that an admin check if this skin is NSFW. - * Unlike other review mutaiton endpoints, this one does not require being logged - * in. - * @gqlField */ - async request_nsfw_review_for_skin( - { md5 }: { md5: string }, - req - ): Promise { - req.log(`Reporting skin with hash "${md5}"`); - // Blow up if there is no skin with this hash - await SkinModel.fromMd5Assert(req.ctx, md5); - req.notify({ type: "REVIEW_REQUESTED", md5 }); - return true; - } +/** + * Mutations for the upload flow + * @gqlField */ +export async function upload(_: Mutation): Promise { + return new UploadMutationResolver(); +} +/** + * Send a message to the admin of the site. Currently this appears in Discord. + * @gqlField */ +export async function send_feedback( + _: Mutation, + { + message, + email, + url, + }: { message: string; email?: string | null; url?: string | null }, + req: Ctx +): Promise { + req.notify({ + type: "GOT_FEEDBACK", + url, + message, + email, + }); + return true; +} + +/** + * Reject skin for tweeting + * + * **Note:** Requires being logged in + * @gqlField */ +export function reject_skin( + _: Mutation, + args: { md5: string }, + req: Ctx +): Promise { + return _reject_skin(args, req); +} + +const _reject_skin = requireAuthed(async ({ md5 }, req: Ctx) => { + req.log(`Rejecting skin with hash "${md5}"`); + const skin = await SkinModel.fromMd5Assert(req.ctx, md5); + if (skin == null) { + return false; + } + await Skins.reject(req.ctx, md5); + req.notify({ type: "REJECTED_SKIN", md5 }); + return true; +}); + +/** + * Approve skin for tweeting + * + * **Note:** Requires being logged in + * @gqlField */ +export function approve_skin( + _: Mutation, + args: { md5: string }, + req: Ctx +): Promise { + return _approve_skin(args, req); +} + +const _approve_skin = requireAuthed(async ({ md5 }, req: Ctx) => { + req.log(`Approving skin with hash "${md5}"`); + const skin = await SkinModel.fromMd5(req.ctx, md5); + if (skin == null) { + return false; + } + await Skins.approve(req.ctx, md5); + req.notify({ type: "APPROVED_SKIN", md5 }); + return true; +}); + +/** + * Mark a skin as NSFW + * + * **Note:** Requires being logged in + * @gqlField */ +export function mark_skin_nsfw( + _: Mutation, + args: { md5: string }, + req: Ctx +): Promise { + return _mark_skin_nsfw(args, req); +} + +const _mark_skin_nsfw = requireAuthed(async ({ md5 }, req: Ctx) => { + req.log(`Approving skin with hash "${md5}"`); + const skin = await SkinModel.fromMd5(req.ctx, md5); + if (skin == null) { + return false; + } + await Skins.markAsNSFW(req.ctx, md5); + req.notify({ type: "MARKED_SKIN_NSFW", md5 }); + return true; +}); + +/** + * Request that an admin check if this skin is NSFW. + * Unlike other review mutaiton endpoints, this one does not require being logged + * in. + * @gqlField */ +export async function request_nsfw_review_for_skin( + _: Mutation, + { md5 }: { md5: string }, + req: Ctx +): Promise { + req.log(`Reporting skin with hash "${md5}"`); + // Blow up if there is no skin with this hash + await SkinModel.fromMd5Assert(req.ctx, md5); + req.notify({ type: "REVIEW_REQUESTED", md5 }); + return true; } diff --git a/packages/skin-database/api/graphql/resolvers/ReviewResolver.ts b/packages/skin-database/api/graphql/resolvers/ReviewResolver.ts index a91196e6..d7cbdacc 100644 --- a/packages/skin-database/api/graphql/resolvers/ReviewResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/ReviewResolver.ts @@ -1,3 +1,4 @@ +import { Ctx } from ".."; import { Rating, ReviewRow } from "../../../types"; import { ISkin } from "./CommonSkinResolver"; import SkinResolver from "./SkinResolver"; @@ -16,7 +17,7 @@ export default class ReviewResolver { * The skin that was reviewed * @gqlField */ - skin(args: never, { ctx }): Promise { + skin(args: unknown, { ctx }: Ctx): Promise { return SkinResolver.fromMd5(ctx, this._model.skin_md5); } diff --git a/packages/skin-database/api/graphql/resolvers/RootResolver.ts b/packages/skin-database/api/graphql/resolvers/RootResolver.ts index f58f22b3..dd3d9618 100644 --- a/packages/skin-database/api/graphql/resolvers/RootResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/RootResolver.ts @@ -9,132 +9,144 @@ import * as Skins from "../../../data/skins"; import { ID, Int } from "grats"; import algoliasearch from "algoliasearch"; -import MutationResolver from "./MutationResolver"; import { knex } from "../../../db"; import ArchiveFileModel from "../../../data/ArchiveFileModel"; import DatabaseStatisticsResolver from "./DatabaseStatisticsResolver"; import { fromId, NodeResolver } from "./NodeResolver"; import ModernSkinsConnection from "../ModernSkinsConnection"; import { ISkin } from "./CommonSkinResolver"; +import { Ctx } from ".."; // These keys are already in the web client, so they are not secret at all. const client = algoliasearch("HQ9I5Z6IM5", "6466695ec3f624a5fccf46ec49680e51"); const index = client.initIndex("Skins"); /** @gqlType Query */ -class RootResolver extends MutationResolver { - /** - * Get a globally unique object by its ID. - * - * https://graphql.org/learn/global-object-identification/ - * @gqlField - */ - async node({ id }: { id: ID }, { ctx }): Promise { - const { graphqlType, id: localId } = fromId(id); - // TODO Use typeResolver - switch (graphqlType) { - case "ClassicSkin": - case "ModernSkin": { - const skin = await SkinModel.fromMd5(ctx, localId); - if (skin == null) { - return null; - } - return SkinResolver.fromModel(skin); +type Query = unknown; + +/** + * Get a globally unique object by its ID. + * + * https://graphql.org/learn/global-object-identification/ + * @gqlField + */ +export async function node( + _: Query, + { id }: { id: ID }, + { ctx }: Ctx +): Promise { + const { graphqlType, id: localId } = fromId(id); + // TODO Use typeResolver + switch (graphqlType) { + case "ClassicSkin": + case "ModernSkin": { + const skin = await SkinModel.fromMd5(ctx, localId); + if (skin == null) { + return null; } + return SkinResolver.fromModel(skin); } + } + return null; +} + +/** + * Get a skin by its MD5 hash + * @gqlField + */ +export async function fetch_skin_by_md5( + _: Query, + { md5 }: { md5: string }, + { ctx }: Ctx +): Promise { + const skin = await SkinModel.fromMd5(ctx, md5); + if (skin == null) { return null; } + return SkinResolver.fromModel(skin); +} - /** - * Get a skin by its MD5 hash - * @gqlField - */ - async fetch_skin_by_md5( - { md5 }: { md5: string }, - { ctx } - ): Promise { - const skin = await SkinModel.fromMd5(ctx, md5); - if (skin == null) { - return null; - } - return SkinResolver.fromModel(skin); +/** + * Get a tweet by its URL + * @gqlField + */ +export async function fetch_tweet_by_url( + _: Query, + { url }: { url: string }, + { ctx }: Ctx +): Promise { + return TweetModel.fromAnything(ctx, url); +} + +/** + * Get an archive.org item by its identifier. You can find this in the URL: + * + * https://archive.org/details// + * @gqlField + */ +export async function fetch_internet_archive_item_by_identifier( + _: Query, + { identifier }: { identifier: string }, + { ctx }: Ctx +): Promise { + return IaItemModel.fromIdentifier(ctx, identifier); +} + +/** + * Fetch archive file by it's MD5 hash + * + * Get information about a file found within a skin's wsz/wal/zip archive. + * @gqlField + */ +export async function fetch_archive_file_by_md5( + _: Query, + { md5 }: { md5: string }, + { ctx }: Ctx +): Promise { + return ArchiveFileModel.fromFileMd5(ctx, md5); +} + +/** + * Search the database using the Algolia search index used by the Museum. + * + * Useful for locating a particular skin. + * @gqlField + */ +export async function search_skins( + _: Query, + { + query, + first = 10, + offset = 0, + }: { query: string; first?: Int; offset?: Int }, + { ctx }: Ctx +): Promise> { + if (first > 1000) { + throw new Error("Can only query 1000 records via search."); } - /** - * Get a tweet by its URL - * @gqlField - */ - async fetch_tweet_by_url( - { url }: { url: string }, - { ctx } - ): Promise { - return TweetModel.fromAnything(ctx, url); - } + const results: { hits: { md5: string }[] } = await index.search(query, { + attributesToRetrieve: ["md5"], + length: first, + offset, + }); - /** - * Get an archive.org item by its identifier. You can find this in the URL: - * - * https://archive.org/details// - * @gqlField - */ - async fetch_internet_archive_item_by_identifier( - { identifier }: { identifier: string }, - { ctx } - ): Promise { - return IaItemModel.fromIdentifier(ctx, identifier); - } + return Promise.all( + results.hits.map(async (hit) => { + const model = await SkinModel.fromMd5Assert(ctx, hit.md5); + return SkinResolver.fromModel(model); + }) + ); +} - /** - * Fetch archive file by it's MD5 hash - * - * Get information about a file found within a skin's wsz/wal/zip archive. - * @gqlField - */ - async fetch_archive_file_by_md5( - { md5 }: { md5: string }, - { ctx } - ): Promise { - return ArchiveFileModel.fromFileMd5(ctx, md5); - } - - /** - * Search the database using the Algolia search index used by the Museum. - * - * Useful for locating a particular skin. - * @gqlField - */ - async search_skins( - { - query, - first = 10, - offset = 0, - }: { query: string; first?: Int; offset?: Int }, - { ctx } - ): Promise> { - if (first > 1000) { - throw new Error("Can only query 1000 records via search."); - } - - const results: { hits: { md5: string }[] } = await index.search(query, { - attributesToRetrieve: ["md5"], - length: first, - offset, - }); - - return Promise.all( - results.hits.map(async (hit) => { - const model = await SkinModel.fromMd5Assert(ctx, hit.md5); - return SkinResolver.fromModel(model); - }) - ); - } - - /** - * All classic skins in the database - * - * **Note:** We don't currently support combining sorting and filtering. - * @gqlField */ - skins({ +/** + * All classic skins in the database + * + * **Note:** We don't currently support combining sorting and filtering. + * @gqlField */ +export function skins( + _: Query, + { first = 10, offset = 0, sort, @@ -142,120 +154,131 @@ class RootResolver extends MutationResolver { }: { first?: Int; offset?: Int; - sort?: SkinsSortOption; - filter?: SkinsFilterOption; - }): SkinsConnection { - if (first > 1000) { - throw new Error("Maximum limit is 1000"); - } - return new SkinsConnection(first, offset, sort, filter); + sort?: SkinsSortOption | null; + filter?: SkinsFilterOption | null; } +): SkinsConnection { + if (first > 1000) { + throw new Error("Maximum limit is 1000"); + } + return new SkinsConnection(first, offset, sort, filter); +} - /** - * All modern skins in the database - * @gqlField */ - async modern_skins({ +/** + * All modern skins in the database + * @gqlField */ +export async function modern_skins( + _: Query, + { first = 10, offset = 0, }: { first?: Int; offset?: Int; - }): Promise { - if (first > 1000) { - throw new Error("Maximum limit is 1000"); - } - return new ModernSkinsConnection(first, offset); } - - /** - * A random skin that needs to be reviewed - * @gqlField */ - async skin_to_review(_args: never, { ctx }): Promise { - if (!ctx.authed()) { - return null; - } - const { md5 } = await Skins.getSkinToReview(); - const model = await SkinModel.fromMd5Assert(ctx, md5); - return SkinResolver.fromModel(model); +): Promise { + if (first > 1000) { + throw new Error("Maximum limit is 1000"); } + return new ModernSkinsConnection(first, offset); +} - /** - * Tweets tweeted by @winampskins - * @gqlField - */ - async tweets({ +/** + * A random skin that needs to be reviewed + * @gqlField */ +export async function skin_to_review( + _: Query, + _args: unknown, + { ctx }: Ctx +): Promise { + if (!ctx.authed()) { + return null; + } + const { md5 } = await Skins.getSkinToReview(); + const model = await SkinModel.fromMd5Assert(ctx, md5); + return SkinResolver.fromModel(model); +} + +/** + * Tweets tweeted by @winampskins + * @gqlField + */ +export async function tweets( + _: Query, + { first = 10, offset = 0, sort, }: { first?: Int; offset?: Int; - sort?: TweetsSortOption; - }): Promise { - if (first > 1000) { - throw new Error("Maximum limit is 1000"); - } - return new TweetsConnection(first, offset, sort); + sort?: TweetsSortOption | null; } - - /** - * The currently authenticated user, if any. - * @gqlField - */ - me(): UserResolver | null { - return new UserResolver(); +): Promise { + if (first > 1000) { + throw new Error("Maximum limit is 1000"); } + return new TweetsConnection(first, offset, sort); +} - /** - * Get the status of a batch of uploads by md5s - * @gqlField - * @deprecated Prefer `upload_statuses` instead, were we operate on ids. - */ - async upload_statuses_by_md5( - { md5s }: { md5s: string[] }, - { ctx } - ): Promise> { - return this._upload_statuses({ keyName: "skin_md5", keys: md5s }, ctx); - } +/** + * The currently authenticated user, if any. + * @gqlField + */ +export function me(_: Query): UserResolver | null { + return new UserResolver(); +} - /** - * Get the status of a batch of uploads by ids - * @gqlField */ - async upload_statuses( - { ids }: { ids: string[] }, - { ctx } - ): Promise> { - return this._upload_statuses({ keyName: "id", keys: ids }, ctx); - } +/** + * Get the status of a batch of uploads by md5s + * @gqlField + * @deprecated Prefer `upload_statuses` instead, were we operate on ids. + */ +export async function upload_statuses_by_md5( + _: Query, + { md5s }: { md5s: string[] }, + { ctx }: Ctx +): Promise> { + return _upload_statuses({ keyName: "skin_md5", keys: md5s }, ctx); +} - // Shared implementation for upload_statuses and upload_statuses_by_md5 - async _upload_statuses({ keyName, keys }, ctx) { - const skins = await knex("skin_uploads") - .whereIn(keyName, keys) - .orderBy("id", "desc") - .select("id", "skin_md5", "status"); +/** + * Get the status of a batch of uploads by ids + * @gqlField */ +export async function upload_statuses( + _: Query, + { ids }: { ids: string[] }, + { ctx }: Ctx +): Promise> { + return _upload_statuses({ keyName: "id", keys: ids }, ctx); +} - return Promise.all( - skins.map(async ({ id, skin_md5, status }) => { - // TODO: Could we avoid fetching the skin if it's not read? - const skinModel = await SkinModel.fromMd5(ctx, skin_md5); - const skin = - skinModel == null ? null : SkinResolver.fromModel(skinModel); - // Most of the time when a skin fails to process, it's due to some infa - // issue on our side, and we can recover. For now, we'll always tell the user - // That processing is just delayed. - status = status === "ERRORED" ? "DELAYED" : status; - return { id, skin, status, upload_md5: skin_md5 }; - }) - ); - } +// Shared implementation for upload_statuses and upload_statuses_by_md5 +async function _upload_statuses({ keyName, keys }, ctx) { + const skins = await knex("skin_uploads") + .whereIn(keyName, keys) + .orderBy("id", "desc") + .select("id", "skin_md5", "status"); - /** - * A namespace for statistics about the database - * @gqlField */ - statistics(): DatabaseStatisticsResolver { - return new DatabaseStatisticsResolver(); - } + return Promise.all( + skins.map(async ({ id, skin_md5, status }) => { + // TODO: Could we avoid fetching the skin if it's not read? + const skinModel = await SkinModel.fromMd5(ctx, skin_md5); + const skin = skinModel == null ? null : SkinResolver.fromModel(skinModel); + // Most of the time when a skin fails to process, it's due to some infa + // issue on our side, and we can recover. For now, we'll always tell the user + // That processing is just delayed. + status = status === "ERRORED" ? "DELAYED" : status; + return { id, skin, status, upload_md5: skin_md5 }; + }) + ); +} + +/** + * A namespace for statistics about the database + * @gqlField */ +export function statistics(_: Query): DatabaseStatisticsResolver { + return new DatabaseStatisticsResolver(); } /** @@ -341,5 +364,3 @@ type SkinUploadStatus = * @deprecated */ | "ARCHIVED"; - -export default RootResolver; diff --git a/packages/skin-database/api/graphql/resolvers/UserResolver.ts b/packages/skin-database/api/graphql/resolvers/UserResolver.ts index b8eb894e..063032aa 100644 --- a/packages/skin-database/api/graphql/resolvers/UserResolver.ts +++ b/packages/skin-database/api/graphql/resolvers/UserResolver.ts @@ -1,7 +1,9 @@ +import { Ctx } from ".."; + /** @gqlType User */ export default class UserResolver { /** @gqlField */ - username(_args: never, { ctx }): string { + username(_args: unknown, { ctx }: Ctx): string | null { return ctx.username; } } diff --git a/packages/skin-database/api/graphql/schema.graphql b/packages/skin-database/api/graphql/schema.graphql index 35c994a9..7bab0694 100644 --- a/packages/skin-database/api/graphql/schema.graphql +++ b/packages/skin-database/api/graphql/schema.graphql @@ -1,252 +1,40 @@ -schema { - query: Query - mutation: Mutation -} - -directive @exported(filename: String!, functionName: String!) on FIELD_DEFINITION - -directive @methodName(name: String!) on FIELD_DEFINITION - -"""A file found within a Winamp Skin's .wsz archive""" -type ArchiveFile { - """ - The date on the file inside the archive. Given in simplified extended ISO - format (ISO 8601). - """ - date: String @methodName(name: "getIsoDate") - """The md5 hash of the file within the archive""" - file_md5: String @methodName(name: "getFileMd5") - """Filename of the file within the archive""" - filename: String @methodName(name: "getFileName") - """Is the file a directory?""" - is_directory: Boolean @methodName(name: "getIsDirectory") - """ - The uncompressed size of the file in bytes. - - **Note:** Will be `null` for directories - """ - size: Int @methodName(name: "getFileSize") - """The skin in which this file was found""" - skin: Skin - """The content of the file, if it's a text file""" - text_content: String @methodName(name: "getTextContent") - """ - A URL to download the file. **Note:** This is powered by a little - serverless Cloudflare function which tries to exctact the file on the fly. - It may not work for all files. - """ - url: String @methodName(name: "getUrl") -} - -"""A classic Winamp skin""" -type ClassicSkin implements Node & Skin { - """List of files contained within the skin's .wsz archive""" - archive_files: [ArchiveFile] @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "archive_files") - """String representation (rgb usually) of the skin's average color""" - average_color: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "average_color") - """URL to download the skin""" - download_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "download_url") - """ - 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( - """ - 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 @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "filename") - """Does the skin include sprite sheets for the media library?""" - has_media_library: Boolean - """GraphQL ID of the skin""" - id: ID! @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "id") - """The skin's "item" at archive.org""" - internet_archive_item: InternetArchiveItem @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "internet_archive_item") - """ - The date on which this skin was last updated in the Algolia search index. - Given in simplified extended ISO format (ISO 8601). - """ - last_algolia_index_update_date: String - """MD5 hash of the skin's file""" - md5: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "md5") - """URL of the skin on the Winamp Skin Museum""" - museum_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "museum_url") - """ - Has the skin been flagged as "not safe for work"?" - """ - nsfw: Boolean @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "nsfw") - """Text of the readme file extracted from the skin""" - readme_text: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "readme_text") - """ - Times that the skin has been reviewed either on the Museum's Tinder-style - review page, or via the Discord bot. - """ - reviews: [Review] @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "reviews") - """URL of a screenshot of the skin""" - screenshot_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "screenshot_url") - """The number of transparent pixels rendered by the skin.""" - transparent_pixels: Int - """Has the skin been tweeted?""" - tweeted: Boolean @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "tweeted") - """List of @winampskins tweets that mentioned the skin.""" - tweets: [Tweet] @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "tweets") - """URL of webamp.org with the skin loaded""" - webamp_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "webamp_url") -} - -"""Statistics about the contents of the Museum's database.""" -type DatabaseStatistics { - """ - The number of skins that have been approved for tweeting. This includes both - tweeted and untweeted skins. - - **Note:** Skins can be both approved and rejected by different users. - """ - approved_skins_count: Int - """ - The number of skins that have been marked as NSFW. - - **Note:** Skins can be approved and rejected by different users. - **Note:** Generally skins that have been marked NSFW are also marked as rejected. - """ - nsfw_skins_count: Int - """ - The number of skins that have been rejected for tweeting. - - **Note:** Skins can be both approved and rejected by different users. - **Note:** Generally skins that have been marked NSFW are also marked as rejected. - """ - rejected_skins_count: Int - """The number of skins that have been approved for tweeting, but not yet tweeted.""" - tweetable_skins_count: Int - """The number of skins in the Museum that have been tweeted by @winampskins""" - tweeted_skins_count: Int - """The total number of classic skins in the Museum's database""" - unique_classic_skins_count: Int - """The number of skins that have never been reviewed.""" - unreviewed_skins_count: Int - """Skins uploads that have errored during processing.""" - uploads_in_error_state_count: Int - """ - Skins uplaods awaiting processing. This can happen when there are a large - number of skin uplaods at the same time, or when the skin uploading processing - pipeline gets stuck. - """ - uploads_pending_processing_count: Int - """Number of skins that have been uploaded to the Museum via the web interface.""" - web_uploads_count: Int -} - -type InternetArchiveItem { - """The Internet Archive's unique identifier for this item""" - identifier: String @methodName(name: "getIdentifier") - """ - The date and time that we last scraped this item's metadata. - **Note:** This field is temporary and will be removed in the future. - The date format is just what we get from the database, and it's ambiguous. - """ - last_metadata_scrape_date_UNSTABLE: String @methodName(name: "getMetadataTimestamp") - """URL to get the Internet Archive's metadata for this item in JSON form.""" - metadata_url: String @methodName(name: "getMetadataUrl") - """Our cached version of the metadata available at \`metadata_url\` (above)""" - raw_metadata_json: String @methodName(name: "getMetadataJSON") - """The skin that this item contains""" - skin: Skin - """The URL where this item can be viewed on the Internet Archive""" - url: String @methodName(name: "getUrl") +# Schema generated by Grats (https://grats.capt.dev) +# Do not manually edit. Regenerate by running `npx grats`. +"""The judgement made about a skin by a moderator""" +enum Rating { + APPROVED + NSFW + REJECTED } """ -A "modern" Winamp skin. These skins use the `.wal` file extension and are free-form. +The current status of a pending upload. -Most functionality in the Winamp Skin Museum is centered around "classic" skins, -which are currently called just `Skin` in this schema. +**Note:** Expect more values here as we try to be more transparent about +the status of a pending uploads. """ -type ModernSkin implements Node & Skin { - """List of files contained within the skin's .wsz archive""" - archive_files: [ArchiveFile] @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "archive_files") - """String representation (rgb usually) of the skin's average color""" - average_color: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "average_color") - """URL to download the skin""" - download_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "download_url") - """ - 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( - """ - 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 @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "filename") - """GraphQL ID of the skin""" - id: ID! @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "id") - """The skin's "item" at archive.org""" - internet_archive_item: InternetArchiveItem @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "internet_archive_item") - """MD5 hash of the skin's file""" - md5: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "md5") - """URL of the skin on the Winamp Skin Museum""" - museum_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "museum_url") - """ - Has the skin been flagged as "not safe for work"?" - """ - nsfw: Boolean @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "nsfw") - """Text of the readme file extracted from the skin""" - readme_text: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "readme_text") - """ - Times that the skin has been reviewed either on the Museum's Tinder-style - review page, or via the Discord bot. - """ - reviews: [Review] @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "reviews") - """URL of a screenshot of the skin""" - screenshot_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "screenshot_url") - """Has the skin been tweeted?""" - tweeted: Boolean @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "tweeted") - """List of @winampskins tweets that mentioned the skin.""" - tweets: [Tweet] @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "tweets") - """URL of webamp.org with the skin loaded""" - webamp_url: String @exported(filename: "../../../../packages/skin-database/dist/api/graphql/resolvers/CommonSkinResolver.js", functionName: "webamp_url") +enum SkinUploadStatus { + ARCHIVED + DELAYED + ERRORED + UPLOAD_REPORTED + URL_REQUESTED } -"""A collection of "modern" Winamp skins""" -type ModernSkinsConnection { - """The total number of skins matching the filter""" - count: Int - """The list of skins""" - nodes: [ModernSkin] +enum SkinsFilterOption { + APPROVED + NSFW + REJECTED + TWEETED } -type Mutation { - """ - Approve skin for tweeting - - **Note:** Requires being logged in - """ - approve_skin(md5: String!): Boolean - """ - Mark a skin as NSFW - - **Note:** Requires being logged in - """ - mark_skin_nsfw(md5: String!): Boolean - """ - Reject skin for tweeting - - **Note:** Requires being logged in - """ - reject_skin(md5: String!): Boolean - """ - Request that an admin check if this skin is NSFW. - Unlike other review mutaiton endpoints, this one does not require being logged - in. - """ - request_nsfw_review_for_skin(md5: String!): Boolean - """Send a message to the admin of the site. Currently this appears in Discord.""" - send_feedback(email: String, message: String!, url: String): Boolean - """Mutations for the upload flow""" - upload: UploadMutations +enum SkinsSortOption { + MUSEUM +} + +enum TweetsSortOption { + LIKES + RETWEETS } """ @@ -258,80 +46,6 @@ interface Node { id: ID! } -type Query { - """ - Fetch archive file by it's MD5 hash - - Get information about a file found within a skin's wsz/wal/zip archive. - """ - fetch_archive_file_by_md5(md5: String!): ArchiveFile - """ - Get an archive.org item by its identifier. You can find this in the URL: - - https://archive.org/details// - """ - fetch_internet_archive_item_by_identifier(identifier: String!): InternetArchiveItem - """Get a skin by its MD5 hash""" - fetch_skin_by_md5(md5: String!): Skin - """Get a tweet by its URL""" - fetch_tweet_by_url(url: String!): Tweet - """The currently authenticated user, if any.""" - me: User - """All modern skins in the database""" - modern_skins(first: Int = 10, offset: Int = 0): ModernSkinsConnection - """ - Get a globally unique object by its ID. - - https://graphql.org/learn/global-object-identification/ - """ - node(id: ID!): Node - """ - Search the database using the Algolia search index used by the Museum. - - Useful for locating a particular skin. - """ - search_skins(first: Int = 10, offset: Int = 0, query: String!): [Skin] - """A random skin that needs to be reviewed""" - skin_to_review: Skin - """ - All classic skins in the database - - **Note:** We don't currently support combining sorting and filtering. - """ - skins(filter: SkinsFilterOption, first: Int = 10, offset: Int = 0, sort: SkinsSortOption): SkinsConnection - """A namespace for statistics about the database""" - statistics: DatabaseStatistics - """Tweets tweeted by @winampskins""" - tweets(first: Int = 10, offset: Int = 0, sort: TweetsSortOption): TweetsConnection - """Get the status of a batch of uploads by ids""" - upload_statuses(ids: [String!]!): [SkinUpload] - """Get the status of a batch of uploads by md5s""" - upload_statuses_by_md5(md5s: [String!]!): [SkinUpload] @deprecated(reason: "Prefer `upload_statuses` instead, were we operate on ids.") -} - -"""The judgement made about a skin by a moderator""" -enum Rating { - APPROVED - NSFW - REJECTED -} - -""" -A review of a skin. Done either on the Museum's Tinder-style -reivew page, or via the Discord bot. -""" -type Review { - """The rating that the user gave the skin""" - rating: Rating - """ - The user who made the review (if known). **Note:** In the early days we didn't - track this, so many will be null. - """ - reviewer: String - """The skin that was reviewed""" - skin: Skin -} - """ A Winamp skin. Could be modern or classic. @@ -378,29 +92,333 @@ interface Skin { screenshot_url: String """Has the skin been tweeted?""" tweeted: Boolean - """List of @winampskins tweets that mentioned the skin.""" + """List of""" tweets: [Tweet] """URL of webamp.org with the skin loaded""" webamp_url: String } -"""A collection of classic Winamp skins""" -type SkinsConnection { +"""Input object used for a user to request an UploadUrl""" +input UploadUrlRequest { + filename: String! + md5: String! +} + +"""A file found within a Winamp Skin's .wsz archive""" +type ArchiveFile { + """ + The date on the file inside the archive. Given in simplified extended ISO + format (ISO 8601). + """ + date: String + """The md5 hash of the file within the archive""" + file_md5: String + """Filename of the file within the archive""" + filename: String + """Is the file a directory?""" + is_directory: Boolean + """ + The uncompressed size of the file in bytes. + + **Note:** Will be `null` for directories + """ + size: Int + """The skin in which this file was found""" + skin: Skin + """The content of the file, if it's a text file""" + text_content: String + """ + A URL to download the file. **Note:** This is powered by a little + serverless Cloudflare function which tries to exctact the file on the fly. + It may not work for all files. + """ + url: String +} + +"""A classic Winamp skin""" +type ClassicSkin implements Node & Skin { + """List of files contained within the skin's .wsz archive""" + archive_files: [ArchiveFile] + """String representation (rgb usually) of the skin's average color""" + average_color: String + """URL to download the skin""" + download_url: String + """ + 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( + """ + 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 + """Does the skin include sprite sheets for the media library?""" + has_media_library: Boolean + """GraphQL ID of the skin""" + id: ID! + """The skin's "item" at archive.org""" + internet_archive_item: InternetArchiveItem + """ + The date on which this skin was last updated in the Algolia search index. + Given in simplified extended ISO format (ISO 8601). + """ + last_algolia_index_update_date: String + """MD5 hash of the skin's file""" + md5: String + """URL of the skin on the Winamp Skin Museum""" + museum_url: String + """ + Has the skin been flagged as "not safe for work"?" + """ + nsfw: Boolean + """Text of the readme file extracted from the skin""" + readme_text: String + """ + Times that the skin has been reviewed either on the Museum's Tinder-style + review page, or via the Discord bot. + """ + reviews: [Review] + """URL of a screenshot of the skin""" + screenshot_url: String + """The number of transparent pixels rendered by the skin.""" + transparent_pixels: Int + """Has the skin been tweeted?""" + tweeted: Boolean + """List of""" + tweets: [Tweet] + """URL of webamp.org with the skin loaded""" + webamp_url: String +} + +"""Statistics about the contents of the Museum's database.""" +type DatabaseStatistics { + """ + The number of skins that have been approved for tweeting. This includes both + tweeted and untweeted skins. + + **Note:** Skins can be both approved and rejected by different users. + """ + approved_skins_count: Int + """ + The number of skins that have been marked as NSFW. + + **Note:** Skins can be approved and rejected by different users. + **Note:** Generally skins that have been marked NSFW are also marked as rejected. + """ + nsfw_skins_count: Int + """ + The number of skins that have been rejected for tweeting. + + **Note:** Skins can be both approved and rejected by different users. + **Note:** Generally skins that have been marked NSFW are also marked as rejected. + """ + rejected_skins_count: Int + """ + The number of skins that have been approved for tweeting, but not yet tweeted. + """ + tweetable_skins_count: Int + """The number of skins in the Museum that have been tweeted by""" + tweeted_skins_count: Int + """The total number of classic skins in the Museum's database""" + unique_classic_skins_count: Int + """The number of skins that have never been reviewed.""" + unreviewed_skins_count: Int + """Skins uploads that have errored during processing.""" + uploads_in_error_state_count: Int + """ + Skins uplaods awaiting processing. This can happen when there are a large + number of skin uplaods at the same time, or when the skin uploading processing + pipeline gets stuck. + """ + uploads_pending_processing_count: Int + """ + Number of skins that have been uploaded to the Museum via the web interface. + """ + web_uploads_count: Int +} + +type InternetArchiveItem { + """The Internet Archive's unique identifier for this item""" + identifier: String + """ + The date and time that we last scraped this item's metadata. + **Note:** This field is temporary and will be removed in the future. + The date format is just what we get from the database, and it's ambiguous. + """ + last_metadata_scrape_date_UNSTABLE: String + """URL to get the Internet Archive's metadata for this item in JSON form.""" + metadata_url: String + """ + Our cached version of the metadata available at \`metadata_url\` (above) + """ + raw_metadata_json: String + """The skin that this item contains""" + skin: Skin + """The URL where this item can be viewed on the Internet Archive""" + url: String +} + +""" +A "modern" Winamp skin. These skins use the `.wal` file extension and are free-form. + +Most functionality in the Winamp Skin Museum is centered around "classic" skins, +which are currently called just `Skin` in this schema. +""" +type ModernSkin implements Node & Skin { + """List of files contained within the skin's .wsz archive""" + archive_files: [ArchiveFile] + """String representation (rgb usually) of the skin's average color""" + average_color: String + """URL to download the skin""" + download_url: String + """ + 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( + """ + 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 + """GraphQL ID of the skin""" + id: ID! + """The skin's "item" at archive.org""" + internet_archive_item: InternetArchiveItem + """MD5 hash of the skin's file""" + md5: String + """URL of the skin on the Winamp Skin Museum""" + museum_url: String + """ + Has the skin been flagged as "not safe for work"?" + """ + nsfw: Boolean + """Text of the readme file extracted from the skin""" + readme_text: String + """ + Times that the skin has been reviewed either on the Museum's Tinder-style + review page, or via the Discord bot. + """ + reviews: [Review] + """URL of a screenshot of the skin""" + screenshot_url: String + """Has the skin been tweeted?""" + tweeted: Boolean + """List of""" + tweets: [Tweet] + """URL of webamp.org with the skin loaded""" + webamp_url: String +} + +"""A collection of "modern" Winamp skins""" +type ModernSkinsConnection { """The total number of skins matching the filter""" count: Int """The list of skins""" - nodes: [Skin] + nodes: [ModernSkin] } -enum SkinsFilterOption { - APPROVED - NSFW - REJECTED - TWEETED +type Mutation { + """ + Approve skin for tweeting + + **Note:** Requires being logged in + """ + approve_skin(md5: String!): Boolean + """ + Mark a skin as NSFW + + **Note:** Requires being logged in + """ + mark_skin_nsfw(md5: String!): Boolean + """ + Reject skin for tweeting + + **Note:** Requires being logged in + """ + reject_skin(md5: String!): Boolean + """ + Request that an admin check if this skin is NSFW. + Unlike other review mutaiton endpoints, this one does not require being logged + in. + """ + request_nsfw_review_for_skin(md5: String!): Boolean + """ + Send a message to the admin of the site. Currently this appears in Discord. + """ + send_feedback(email: String, message: String!, url: String): Boolean + """Mutations for the upload flow""" + upload: UploadMutations } -enum SkinsSortOption { - MUSEUM +type Query { + """ + Fetch archive file by it's MD5 hash + + Get information about a file found within a skin's wsz/wal/zip archive. + """ + fetch_archive_file_by_md5(md5: String!): ArchiveFile + """ + Get an archive.org item by its identifier. You can find this in the URL: + + https://archive.org/details// + """ + fetch_internet_archive_item_by_identifier(identifier: String!): InternetArchiveItem + """Get a skin by its MD5 hash""" + fetch_skin_by_md5(md5: String!): Skin + """Get a tweet by its URL""" + fetch_tweet_by_url(url: String!): Tweet + """The currently authenticated user, if any.""" + me: User + """All modern skins in the database""" + modern_skins(first: Int! = 10, offset: Int! = 0): ModernSkinsConnection + """ + Get a globally unique object by its ID. + + https://graphql.org/learn/global-object-identification/ + """ + node(id: ID!): Node + """ + Search the database using the Algolia search index used by the Museum. + + Useful for locating a particular skin. + """ + search_skins(first: Int! = 10, offset: Int! = 0, query: String!): [Skin] + """A random skin that needs to be reviewed""" + skin_to_review: Skin + """ + All classic skins in the database + + **Note:** We don't currently support combining sorting and filtering. + """ + skins(filter: SkinsFilterOption, first: Int! = 10, offset: Int! = 0, sort: SkinsSortOption): SkinsConnection + """A namespace for statistics about the database""" + statistics: DatabaseStatistics + """Tweets tweeted by""" + tweets(first: Int! = 10, offset: Int! = 0, sort: TweetsSortOption): TweetsConnection + """Get the status of a batch of uploads by ids""" + upload_statuses(ids: [String!]!): [SkinUpload] + """Get the status of a batch of uploads by md5s""" + upload_statuses_by_md5(md5s: [String!]!): [SkinUpload] @deprecated(reason: "Prefer `upload_statuses` instead, were we operate on ids.") +} + +""" +A review of a skin. Done either on the Museum's Tinder-style +reivew page, or via the Discord bot. +""" +type Review { + """The rating that the user gave the skin""" + rating: Rating + """ + The user who made the review (if known). **Note:** In the early days we didn't + track this, so many will be null. + """ + reviewer: String + """The skin that was reviewed""" + skin: Skin } """Information about an attempt to upload a skin to the Museum.""" @@ -416,26 +434,24 @@ type SkinUpload { upload_md5: String } -""" -The current status of a pending upload. - -**Note:** Expect more values here as we try to be more transparent about -the status of a pending uploads. -""" -enum SkinUploadStatus { - ARCHIVED - DELAYED - ERRORED - UPLOAD_REPORTED - URL_REQUESTED +"""A collection of classic Winamp skins""" +type SkinsConnection { + """The total number of skins matching the filter""" + count: Int + """The list of skins""" + nodes: [Skin] } -"""A tweet made by @winampskins mentioning a Winamp skin""" +"""A tweet made by""" type Tweet { - """Number of likes the tweet has received. Updated nightly. (Note: Recent likes on older tweets may not be reflected here)""" - likes: Int @methodName(name: "getLikes") - """Number of retweets the tweet has received. Updated nightly. (Note: Recent retweets on older tweets may not be reflected here)""" - retweets: Int @methodName(name: "getRetweets") + """ + Number of likes the tweet has received. Updated nightly. (Note: Recent likes on older tweets may not be reflected here) + """ + likes: Int + """ + Number of retweets the tweet has received. Updated nightly. (Note: Recent retweets on older tweets may not be reflected here) + """ + retweets: Int """The skin featured in this Tweet""" skin: Skin """ @@ -443,10 +459,10 @@ type Tweet { _which_ skins were tweeted, not any info about the actual tweet. This means we don't always know the URL of the tweet. """ - url: String @methodName(name: "getUrl") + url: String } -"""A collection of tweets made by the @winampskins bot""" +"""A collection of tweets made by the""" type TweetsConnection { """The total number of tweets""" count: Int @@ -454,11 +470,6 @@ type TweetsConnection { nodes: [Tweet] } -enum TweetsSortOption { - LIKES - RETWEETS -} - """ Mutations for the upload flow @@ -490,12 +501,6 @@ type UploadUrl { url: String } -"""Input object used for a user to request an UploadUrl""" -input UploadUrlRequest { - filename: String! - md5: String! -} - type User { username: String } diff --git a/packages/skin-database/api/graphql/schema.ts b/packages/skin-database/api/graphql/schema.ts new file mode 100644 index 00000000..d701d92d --- /dev/null +++ b/packages/skin-database/api/graphql/schema.ts @@ -0,0 +1,1249 @@ +/** + * Executable schema generated by Grats (https://grats.capt.dev) + * Do not manually edit. Regenerate by running `npx grats`. + */ +import { fetch_archive_file_by_md5 as queryFetch_archive_file_by_md5Resolver } from "./resolvers/RootResolver"; +import { fetch_internet_archive_item_by_identifier as queryFetch_internet_archive_item_by_identifierResolver } from "./resolvers/RootResolver"; +import { fetch_skin_by_md5 as queryFetch_skin_by_md5Resolver } from "./resolvers/RootResolver"; +import { fetch_tweet_by_url as queryFetch_tweet_by_urlResolver } from "./resolvers/RootResolver"; +import { me as queryMeResolver } from "./resolvers/RootResolver"; +import { archive_files as modernSkinArchive_filesResolver } from "./resolvers/CommonSkinResolver"; +import { average_color as modernSkinAverage_colorResolver } from "./resolvers/CommonSkinResolver"; +import { download_url as modernSkinDownload_urlResolver } from "./resolvers/CommonSkinResolver"; +import { filename as modernSkinFilenameResolver } from "./resolvers/CommonSkinResolver"; +import { id as modernSkinIdResolver } from "./resolvers/CommonSkinResolver"; +import { internet_archive_item as modernSkinInternet_archive_itemResolver } from "./resolvers/CommonSkinResolver"; +import { md5 as modernSkinMd5Resolver } from "./resolvers/CommonSkinResolver"; +import { museum_url as modernSkinMuseum_urlResolver } from "./resolvers/CommonSkinResolver"; +import { nsfw as modernSkinNsfwResolver } from "./resolvers/CommonSkinResolver"; +import { readme_text as modernSkinReadme_textResolver } from "./resolvers/CommonSkinResolver"; +import { reviews as modernSkinReviewsResolver } from "./resolvers/CommonSkinResolver"; +import { screenshot_url as modernSkinScreenshot_urlResolver } from "./resolvers/CommonSkinResolver"; +import { tweeted as modernSkinTweetedResolver } from "./resolvers/CommonSkinResolver"; +import { tweets as modernSkinTweetsResolver } from "./resolvers/CommonSkinResolver"; +import { webamp_url as modernSkinWebamp_urlResolver } from "./resolvers/CommonSkinResolver"; +import { modern_skins as queryModern_skinsResolver } from "./resolvers/RootResolver"; +import { node as queryNodeResolver } from "./resolvers/RootResolver"; +import { search_skins as querySearch_skinsResolver } from "./resolvers/RootResolver"; +import { skin_to_review as querySkin_to_reviewResolver } from "./resolvers/RootResolver"; +import { skins as querySkinsResolver } from "./resolvers/RootResolver"; +import { statistics as queryStatisticsResolver } from "./resolvers/RootResolver"; +import { tweets as queryTweetsResolver } from "./resolvers/RootResolver"; +import { upload_statuses as queryUpload_statusesResolver } from "./resolvers/RootResolver"; +import { upload_statuses_by_md5 as queryUpload_statuses_by_md5Resolver } from "./resolvers/RootResolver"; +import { approve_skin as mutationApprove_skinResolver } from "./resolvers/MutationResolver"; +import { mark_skin_nsfw as mutationMark_skin_nsfwResolver } from "./resolvers/MutationResolver"; +import { reject_skin as mutationReject_skinResolver } from "./resolvers/MutationResolver"; +import { request_nsfw_review_for_skin as mutationRequest_nsfw_review_for_skinResolver } from "./resolvers/MutationResolver"; +import { send_feedback as mutationSend_feedbackResolver } from "./resolvers/MutationResolver"; +import { upload as mutationUploadResolver } from "./resolvers/MutationResolver"; +import { archive_files as classicSkinArchive_filesResolver } from "./resolvers/CommonSkinResolver"; +import { average_color as classicSkinAverage_colorResolver } from "./resolvers/CommonSkinResolver"; +import { download_url as classicSkinDownload_urlResolver } from "./resolvers/CommonSkinResolver"; +import { filename as classicSkinFilenameResolver } from "./resolvers/CommonSkinResolver"; +import { id as classicSkinIdResolver } from "./resolvers/CommonSkinResolver"; +import { internet_archive_item as classicSkinInternet_archive_itemResolver } from "./resolvers/CommonSkinResolver"; +import { md5 as classicSkinMd5Resolver } from "./resolvers/CommonSkinResolver"; +import { museum_url as classicSkinMuseum_urlResolver } from "./resolvers/CommonSkinResolver"; +import { nsfw as classicSkinNsfwResolver } from "./resolvers/CommonSkinResolver"; +import { readme_text as classicSkinReadme_textResolver } from "./resolvers/CommonSkinResolver"; +import { reviews as classicSkinReviewsResolver } from "./resolvers/CommonSkinResolver"; +import { screenshot_url as classicSkinScreenshot_urlResolver } from "./resolvers/CommonSkinResolver"; +import { tweeted as classicSkinTweetedResolver } from "./resolvers/CommonSkinResolver"; +import { tweets as classicSkinTweetsResolver } from "./resolvers/CommonSkinResolver"; +import { webamp_url as classicSkinWebamp_urlResolver } from "./resolvers/CommonSkinResolver"; +import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLBoolean, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLID, GraphQLEnumType, GraphQLInputObjectType } from "graphql"; +export function getSchema(): GraphQLSchema { + const InternetArchiveItemType: GraphQLObjectType = new GraphQLObjectType({ + name: "InternetArchiveItem", + fields() { + return { + identifier: { + description: "The Internet Archive's unique identifier for this item", + name: "identifier", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getIdentifier(source, args, context, info); + } + }, + last_metadata_scrape_date_UNSTABLE: { + description: "The date and time that we last scraped this item's metadata.\n**Note:** This field is temporary and will be removed in the future.\nThe date format is just what we get from the database, and it's ambiguous.", + name: "last_metadata_scrape_date_UNSTABLE", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getMetadataTimestamp(source, args, context, info); + } + }, + metadata_url: { + description: "URL to get the Internet Archive's metadata for this item in JSON form.", + name: "metadata_url", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getMetadataUrl(source, args, context, info); + } + }, + raw_metadata_json: { + description: "Our cached version of the metadata available at \\`metadata_url\\` (above)", + name: "raw_metadata_json", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getMetadataJSON(source, args, context, info); + } + }, + skin: { + description: "The skin that this item contains", + name: "skin", + type: SkinType + }, + url: { + description: "The URL where this item can be viewed on the Internet Archive", + name: "url", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getUrl(source, args, context, info); + } + } + }; + } + }); + const RatingType: GraphQLEnumType = new GraphQLEnumType({ + description: "The judgement made about a skin by a moderator", + name: "Rating", + values: { + APPROVED: { + value: "APPROVED" + }, + NSFW: { + value: "NSFW" + }, + REJECTED: { + value: "REJECTED" + } + } + }); + const ReviewType: GraphQLObjectType = new GraphQLObjectType({ + name: "Review", + description: "A review of a skin. Done either on the Museum's Tinder-style\nreivew page, or via the Discord bot.", + fields() { + return { + rating: { + description: "The rating that the user gave the skin", + name: "rating", + type: RatingType + }, + reviewer: { + description: "The user who made the review (if known). **Note:** In the early days we didn't\ntrack this, so many will be null.", + name: "reviewer", + type: GraphQLString + }, + skin: { + description: "The skin that was reviewed", + name: "skin", + type: SkinType + } + }; + } + }); + const TweetType: GraphQLObjectType = new GraphQLObjectType({ + name: "Tweet", + description: "A tweet made by", + fields() { + return { + likes: { + description: "Number of likes the tweet has received. Updated nightly. (Note: Recent likes on older tweets may not be reflected here)", + name: "likes", + type: GraphQLInt, + resolve(source, args, context, info) { + return source.getLikes(source, args, context, info); + } + }, + retweets: { + description: "Number of retweets the tweet has received. Updated nightly. (Note: Recent retweets on older tweets may not be reflected here)", + name: "retweets", + type: GraphQLInt, + resolve(source, args, context, info) { + return source.getRetweets(source, args, context, info); + } + }, + skin: { + description: "The skin featured in this Tweet", + name: "skin", + type: SkinType + }, + url: { + description: "URL of the tweet. **Note:** Early on in the bot's life we just recorded\n_which_ skins were tweeted, not any info about the actual tweet. This means we\ndon't always know the URL of the tweet.", + name: "url", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getUrl(source, args, context, info); + } + } + }; + } + }); + const SkinType: GraphQLInterfaceType = new GraphQLInterfaceType({ + description: "A Winamp skin. Could be modern or classic.\n\n**Note**: At some point in the future, this might be renamed to `Skin`.", + name: "Skin", + fields() { + return { + archive_files: { + description: "List of files contained within the skin's .wsz archive", + name: "archive_files", + type: new GraphQLList(ArchiveFileType) + }, + average_color: { + description: "String representation (rgb usually) of the skin's average color", + name: "average_color", + type: GraphQLString + }, + download_url: { + description: "URL to download the skin", + name: "download_url", + type: GraphQLString + }, + filename: { + description: "Filename of skin when uploaded to the Museum. Note: In some cases a skin\nhas been uploaded under multiple names. Here we just pick one.", + name: "filename", + type: GraphQLString, + args: { + normalize_extension: { + description: "If true, the the correct file extension (.wsz or .wal) will be .\nOtherwise, the original user-uploaded file extension will be used.", + name: "normalize_extension", + type: GraphQLBoolean, + defaultValue: false + } + } + }, + id: { + description: "GraphQL ID of the skin", + name: "id", + type: new GraphQLNonNull(GraphQLID) + }, + internet_archive_item: { + description: "The skin's \"item\" at archive.org", + name: "internet_archive_item", + type: InternetArchiveItemType + }, + md5: { + description: "MD5 hash of the skin's file", + name: "md5", + type: GraphQLString + }, + museum_url: { + description: "URL of the skin on the Winamp Skin Museum", + name: "museum_url", + type: GraphQLString + }, + nsfw: { + description: "Has the skin been flagged as \"not safe for work\"?\"", + name: "nsfw", + type: GraphQLBoolean + }, + readme_text: { + description: "Text of the readme file extracted from the skin", + name: "readme_text", + type: GraphQLString + }, + reviews: { + description: "Times that the skin has been reviewed either on the Museum's Tinder-style\nreview page, or via the Discord bot.", + name: "reviews", + type: new GraphQLList(ReviewType) + }, + screenshot_url: { + description: "URL of a screenshot of the skin", + name: "screenshot_url", + type: GraphQLString + }, + tweeted: { + description: "Has the skin been tweeted?", + name: "tweeted", + type: GraphQLBoolean + }, + tweets: { + description: "List of", + name: "tweets", + type: new GraphQLList(TweetType) + }, + webamp_url: { + description: "URL of webamp.org with the skin loaded", + name: "webamp_url", + type: GraphQLString + } + }; + } + }); + const ArchiveFileType: GraphQLObjectType = new GraphQLObjectType({ + name: "ArchiveFile", + description: "A file found within a Winamp Skin's .wsz archive", + fields() { + return { + date: { + description: "The date on the file inside the archive. Given in simplified extended ISO\nformat (ISO 8601).", + name: "date", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getIsoDate(source, args, context, info); + } + }, + file_md5: { + description: "The md5 hash of the file within the archive", + name: "file_md5", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getFileMd5(source, args, context, info); + } + }, + filename: { + description: "Filename of the file within the archive", + name: "filename", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getFileName(source, args, context, info); + } + }, + is_directory: { + description: "Is the file a directory?", + name: "is_directory", + type: GraphQLBoolean, + resolve(source, args, context, info) { + return source.getIsDirectory(source, args, context, info); + } + }, + size: { + description: "The uncompressed size of the file in bytes.\n\n**Note:** Will be `null` for directories", + name: "size", + type: GraphQLInt, + resolve(source, args, context, info) { + return source.getFileSize(source, args, context, info); + } + }, + skin: { + description: "The skin in which this file was found", + name: "skin", + type: SkinType + }, + text_content: { + description: "The content of the file, if it's a text file", + name: "text_content", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getTextContent(source, args, context, info); + } + }, + url: { + description: "A URL to download the file. **Note:** This is powered by a little\nserverless Cloudflare function which tries to exctact the file on the fly.\nIt may not work for all files.", + name: "url", + type: GraphQLString, + resolve(source, args, context, info) { + return source.getUrl(source, args, context, info); + } + } + }; + } + }); + const UserType: GraphQLObjectType = new GraphQLObjectType({ + name: "User", + fields() { + return { + username: { + name: "username", + type: GraphQLString + } + }; + } + }); + const NodeType: GraphQLInterfaceType = new GraphQLInterfaceType({ + description: "A globally unique object. The `id` here is intended only for use within\nGraphQL.\nhttps://graphql.org/learn/global-object-identification/", + name: "Node", + fields() { + return { + id: { + name: "id", + type: new GraphQLNonNull(GraphQLID) + } + }; + } + }); + const ModernSkinType: GraphQLObjectType = new GraphQLObjectType({ + name: "ModernSkin", + description: "A \"modern\" Winamp skin. These skins use the `.wal` file extension and are free-form.\n\nMost functionality in the Winamp Skin Museum is centered around \"classic\" skins,\nwhich are currently called just `Skin` in this schema.", + fields() { + return { + archive_files: { + description: "List of files contained within the skin's .wsz archive", + name: "archive_files", + type: new GraphQLList(ArchiveFileType), + resolve(source) { + return modernSkinArchive_filesResolver(source); + } + }, + average_color: { + description: "String representation (rgb usually) of the skin's average color", + name: "average_color", + type: GraphQLString, + resolve(source) { + return modernSkinAverage_colorResolver(source); + } + }, + download_url: { + description: "URL to download the skin", + name: "download_url", + type: GraphQLString, + resolve(source) { + return modernSkinDownload_urlResolver(source); + } + }, + filename: { + description: "Filename of skin when uploaded to the Museum. Note: In some cases a skin\nhas been uploaded under multiple names. Here we just pick one.", + name: "filename", + type: GraphQLString, + args: { + normalize_extension: { + description: "If true, the the correct file extension (.wsz or .wal) will be .\nOtherwise, the original user-uploaded file extension will be used.", + name: "normalize_extension", + type: GraphQLBoolean, + defaultValue: false + } + }, + resolve(source, args) { + return modernSkinFilenameResolver(source, args); + } + }, + id: { + description: "GraphQL ID of the skin", + name: "id", + type: new GraphQLNonNull(GraphQLID), + resolve(source) { + return modernSkinIdResolver(source); + } + }, + internet_archive_item: { + description: "The skin's \"item\" at archive.org", + name: "internet_archive_item", + type: InternetArchiveItemType, + resolve(source) { + return modernSkinInternet_archive_itemResolver(source); + } + }, + md5: { + description: "MD5 hash of the skin's file", + name: "md5", + type: GraphQLString, + resolve(source) { + return modernSkinMd5Resolver(source); + } + }, + museum_url: { + description: "URL of the skin on the Winamp Skin Museum", + name: "museum_url", + type: GraphQLString, + resolve(source) { + return modernSkinMuseum_urlResolver(source); + } + }, + nsfw: { + description: "Has the skin been flagged as \"not safe for work\"?\"", + name: "nsfw", + type: GraphQLBoolean, + resolve(source) { + return modernSkinNsfwResolver(source); + } + }, + readme_text: { + description: "Text of the readme file extracted from the skin", + name: "readme_text", + type: GraphQLString, + resolve(source) { + return modernSkinReadme_textResolver(source); + } + }, + reviews: { + description: "Times that the skin has been reviewed either on the Museum's Tinder-style\nreview page, or via the Discord bot.", + name: "reviews", + type: new GraphQLList(ReviewType), + resolve(source) { + return modernSkinReviewsResolver(source); + } + }, + screenshot_url: { + description: "URL of a screenshot of the skin", + name: "screenshot_url", + type: GraphQLString, + resolve(source) { + return modernSkinScreenshot_urlResolver(source); + } + }, + tweeted: { + description: "Has the skin been tweeted?", + name: "tweeted", + type: GraphQLBoolean, + resolve(source) { + return modernSkinTweetedResolver(source); + } + }, + tweets: { + description: "List of", + name: "tweets", + type: new GraphQLList(TweetType), + resolve(source) { + return modernSkinTweetsResolver(source); + } + }, + webamp_url: { + description: "URL of webamp.org with the skin loaded", + name: "webamp_url", + type: GraphQLString, + resolve(source) { + return modernSkinWebamp_urlResolver(source); + } + } + }; + }, + interfaces() { + return [NodeType, SkinType]; + } + }); + const ModernSkinsConnectionType: GraphQLObjectType = new GraphQLObjectType({ + name: "ModernSkinsConnection", + description: "A collection of \"modern\" Winamp skins", + fields() { + return { + count: { + description: "The total number of skins matching the filter", + name: "count", + type: GraphQLInt + }, + nodes: { + description: "The list of skins", + name: "nodes", + type: new GraphQLList(ModernSkinType) + } + }; + } + }); + const SkinsConnectionType: GraphQLObjectType = new GraphQLObjectType({ + name: "SkinsConnection", + description: "A collection of classic Winamp skins", + fields() { + return { + count: { + description: "The total number of skins matching the filter", + name: "count", + type: GraphQLInt + }, + nodes: { + description: "The list of skins", + name: "nodes", + type: new GraphQLList(SkinType) + } + }; + } + }); + const SkinsFilterOptionType: GraphQLEnumType = new GraphQLEnumType({ + name: "SkinsFilterOption", + values: { + APPROVED: { + value: "APPROVED" + }, + NSFW: { + value: "NSFW" + }, + REJECTED: { + value: "REJECTED" + }, + TWEETED: { + value: "TWEETED" + } + } + }); + const SkinsSortOptionType: GraphQLEnumType = new GraphQLEnumType({ + name: "SkinsSortOption", + values: { + MUSEUM: { + value: "MUSEUM" + } + } + }); + const DatabaseStatisticsType: GraphQLObjectType = new GraphQLObjectType({ + name: "DatabaseStatistics", + description: "Statistics about the contents of the Museum's database.", + fields() { + return { + approved_skins_count: { + description: "The number of skins that have been approved for tweeting. This includes both\ntweeted and untweeted skins.\n\n**Note:** Skins can be both approved and rejected by different users.", + name: "approved_skins_count", + type: GraphQLInt + }, + nsfw_skins_count: { + description: "The number of skins that have been marked as NSFW.\n\n**Note:** Skins can be approved and rejected by different users.\n**Note:** Generally skins that have been marked NSFW are also marked as rejected.", + name: "nsfw_skins_count", + type: GraphQLInt + }, + rejected_skins_count: { + description: "The number of skins that have been rejected for tweeting.\n\n**Note:** Skins can be both approved and rejected by different users.\n**Note:** Generally skins that have been marked NSFW are also marked as rejected.", + name: "rejected_skins_count", + type: GraphQLInt + }, + tweetable_skins_count: { + description: "The number of skins that have been approved for tweeting, but not yet tweeted.", + name: "tweetable_skins_count", + type: GraphQLInt + }, + tweeted_skins_count: { + description: "The number of skins in the Museum that have been tweeted by", + name: "tweeted_skins_count", + type: GraphQLInt + }, + unique_classic_skins_count: { + description: "The total number of classic skins in the Museum's database", + name: "unique_classic_skins_count", + type: GraphQLInt + }, + unreviewed_skins_count: { + description: "The number of skins that have never been reviewed.", + name: "unreviewed_skins_count", + type: GraphQLInt + }, + uploads_in_error_state_count: { + description: "Skins uploads that have errored during processing.", + name: "uploads_in_error_state_count", + type: GraphQLInt + }, + uploads_pending_processing_count: { + description: "Skins uplaods awaiting processing. This can happen when there are a large\nnumber of skin uplaods at the same time, or when the skin uploading processing\npipeline gets stuck.", + name: "uploads_pending_processing_count", + type: GraphQLInt + }, + web_uploads_count: { + description: "Number of skins that have been uploaded to the Museum via the web interface.", + name: "web_uploads_count", + type: GraphQLInt + } + }; + } + }); + const TweetsConnectionType: GraphQLObjectType = new GraphQLObjectType({ + name: "TweetsConnection", + description: "A collection of tweets made by the", + fields() { + return { + count: { + description: "The total number of tweets", + name: "count", + type: GraphQLInt + }, + nodes: { + description: "The list of tweets", + name: "nodes", + type: new GraphQLList(TweetType) + } + }; + } + }); + const TweetsSortOptionType: GraphQLEnumType = new GraphQLEnumType({ + name: "TweetsSortOption", + values: { + LIKES: { + value: "LIKES" + }, + RETWEETS: { + value: "RETWEETS" + } + } + }); + const SkinUploadStatusType: GraphQLEnumType = new GraphQLEnumType({ + description: "The current status of a pending upload.\n\n**Note:** Expect more values here as we try to be more transparent about\nthe status of a pending uploads.", + name: "SkinUploadStatus", + values: { + ARCHIVED: { + value: "ARCHIVED" + }, + DELAYED: { + value: "DELAYED" + }, + ERRORED: { + value: "ERRORED" + }, + UPLOAD_REPORTED: { + value: "UPLOAD_REPORTED" + }, + URL_REQUESTED: { + value: "URL_REQUESTED" + } + } + }); + const SkinUploadType: GraphQLObjectType = new GraphQLObjectType({ + name: "SkinUpload", + description: "Information about an attempt to upload a skin to the Museum.", + fields() { + return { + id: { + name: "id", + type: GraphQLString + }, + skin: { + description: "Skin that was uploaded. **Note:** This is null if the skin has not yet been\nfully processed. (status == ARCHIVED)", + name: "skin", + type: SkinType + }, + status: { + name: "status", + type: SkinUploadStatusType + }, + upload_md5: { + description: "Md5 hash given when requesting the upload URL.", + name: "upload_md5", + type: GraphQLString + } + }; + } + }); + const QueryType: GraphQLObjectType = new GraphQLObjectType({ + name: "Query", + fields() { + return { + fetch_archive_file_by_md5: { + description: "Fetch archive file by it's MD5 hash\n\nGet information about a file found within a skin's wsz/wal/zip archive.", + name: "fetch_archive_file_by_md5", + type: ArchiveFileType, + args: { + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return queryFetch_archive_file_by_md5Resolver(source, args, context); + } + }, + fetch_internet_archive_item_by_identifier: { + description: "Get an archive.org item by its identifier. You can find this in the URL:\n\nhttps://archive.org/details//", + name: "fetch_internet_archive_item_by_identifier", + type: InternetArchiveItemType, + args: { + identifier: { + name: "identifier", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return queryFetch_internet_archive_item_by_identifierResolver(source, args, context); + } + }, + fetch_skin_by_md5: { + description: "Get a skin by its MD5 hash", + name: "fetch_skin_by_md5", + type: SkinType, + args: { + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return queryFetch_skin_by_md5Resolver(source, args, context); + } + }, + fetch_tweet_by_url: { + description: "Get a tweet by its URL", + name: "fetch_tweet_by_url", + type: TweetType, + args: { + url: { + name: "url", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return queryFetch_tweet_by_urlResolver(source, args, context); + } + }, + me: { + description: "The currently authenticated user, if any.", + name: "me", + type: UserType, + resolve(source) { + return queryMeResolver(source); + } + }, + modern_skins: { + description: "All modern skins in the database", + name: "modern_skins", + type: ModernSkinsConnectionType, + args: { + first: { + name: "first", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 10 + }, + offset: { + name: "offset", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 0 + } + }, + resolve(source, args) { + return queryModern_skinsResolver(source, args); + } + }, + node: { + description: "Get a globally unique object by its ID.\n\nhttps://graphql.org/learn/global-object-identification/", + name: "node", + type: NodeType, + args: { + id: { + name: "id", + type: new GraphQLNonNull(GraphQLID) + } + }, + resolve(source, args, context) { + return queryNodeResolver(source, args, context); + } + }, + search_skins: { + description: "Search the database using the Algolia search index used by the Museum.\n\nUseful for locating a particular skin.", + name: "search_skins", + type: new GraphQLList(SkinType), + args: { + first: { + name: "first", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 10 + }, + offset: { + name: "offset", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 0 + }, + query: { + name: "query", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return querySearch_skinsResolver(source, args, context); + } + }, + skin_to_review: { + description: "A random skin that needs to be reviewed", + name: "skin_to_review", + type: SkinType, + resolve(source, args, context) { + return querySkin_to_reviewResolver(source, args, context); + } + }, + skins: { + description: "All classic skins in the database\n\n**Note:** We don't currently support combining sorting and filtering.", + name: "skins", + type: SkinsConnectionType, + args: { + filter: { + name: "filter", + type: SkinsFilterOptionType + }, + first: { + name: "first", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 10 + }, + offset: { + name: "offset", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 0 + }, + sort: { + name: "sort", + type: SkinsSortOptionType + } + }, + resolve(source, args) { + return querySkinsResolver(source, args); + } + }, + statistics: { + description: "A namespace for statistics about the database", + name: "statistics", + type: DatabaseStatisticsType, + resolve(source) { + return queryStatisticsResolver(source); + } + }, + tweets: { + description: "Tweets tweeted by", + name: "tweets", + type: TweetsConnectionType, + args: { + first: { + name: "first", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 10 + }, + offset: { + name: "offset", + type: new GraphQLNonNull(GraphQLInt), + defaultValue: 0 + }, + sort: { + name: "sort", + type: TweetsSortOptionType + } + }, + resolve(source, args) { + return queryTweetsResolver(source, args); + } + }, + upload_statuses: { + description: "Get the status of a batch of uploads by ids", + name: "upload_statuses", + type: new GraphQLList(SkinUploadType), + args: { + ids: { + name: "ids", + type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) + } + }, + resolve(source, args, context) { + return queryUpload_statusesResolver(source, args, context); + } + }, + upload_statuses_by_md5: { + description: "Get the status of a batch of uploads by md5s", + deprecationReason: "Prefer `upload_statuses` instead, were we operate on ids.", + name: "upload_statuses_by_md5", + type: new GraphQLList(SkinUploadType), + args: { + md5s: { + name: "md5s", + type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLString))) + } + }, + resolve(source, args, context) { + return queryUpload_statuses_by_md5Resolver(source, args, context); + } + } + }; + } + }); + const UploadUrlType: GraphQLObjectType = new GraphQLObjectType({ + name: "UploadUrl", + description: "A URL that the client can use to upload a skin to S3, and then notify the server\nwhen they're done.", + fields() { + return { + id: { + name: "id", + type: GraphQLString + }, + md5: { + name: "md5", + type: GraphQLString + }, + url: { + name: "url", + type: GraphQLString + } + }; + } + }); + const UploadUrlRequestType: GraphQLInputObjectType = new GraphQLInputObjectType({ + description: "Input object used for a user to request an UploadUrl", + name: "UploadUrlRequest", + fields() { + return { + filename: { + name: "filename", + type: new GraphQLNonNull(GraphQLString) + }, + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }; + } + }); + const UploadMutationsType: GraphQLObjectType = new GraphQLObjectType({ + name: "UploadMutations", + description: "Mutations for the upload flow\n\n1. The user finds the md5 hash of their local files.\n2. (`get_upload_urls`) The user requests upload URLs for each of their files.\n3. The server returns upload URLs for each of their files which are not already in the collection.\n4. The user uploads each of their files to the URLs returned in step 3.\n5. (`report_skin_uploaded`) The user notifies the server that they're done uploading.\n6. (TODO) The user polls for the status of their uploads.", + fields() { + return { + get_upload_urls: { + description: "Get a (possibly incompelte) list of UploadUrls for each of the files. If an\nUploadUrl is not returned for a given hash, it means the file is already in\nthe collection.", + name: "get_upload_urls", + type: new GraphQLList(UploadUrlType), + args: { + files: { + name: "files", + type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(UploadUrlRequestType))) + } + } + }, + report_skin_uploaded: { + description: "Notify the server that the user is done uploading.", + name: "report_skin_uploaded", + type: GraphQLBoolean, + args: { + id: { + name: "id", + type: new GraphQLNonNull(GraphQLString) + }, + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + } + } + }; + } + }); + const MutationType: GraphQLObjectType = new GraphQLObjectType({ + name: "Mutation", + fields() { + return { + approve_skin: { + description: "Approve skin for tweeting\n\n**Note:** Requires being logged in", + name: "approve_skin", + type: GraphQLBoolean, + args: { + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return mutationApprove_skinResolver(source, args, context); + } + }, + mark_skin_nsfw: { + description: "Mark a skin as NSFW\n\n**Note:** Requires being logged in", + name: "mark_skin_nsfw", + type: GraphQLBoolean, + args: { + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return mutationMark_skin_nsfwResolver(source, args, context); + } + }, + reject_skin: { + description: "Reject skin for tweeting\n\n**Note:** Requires being logged in", + name: "reject_skin", + type: GraphQLBoolean, + args: { + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return mutationReject_skinResolver(source, args, context); + } + }, + request_nsfw_review_for_skin: { + description: "Request that an admin check if this skin is NSFW.\nUnlike other review mutaiton endpoints, this one does not require being logged\nin.", + name: "request_nsfw_review_for_skin", + type: GraphQLBoolean, + args: { + md5: { + name: "md5", + type: new GraphQLNonNull(GraphQLString) + } + }, + resolve(source, args, context) { + return mutationRequest_nsfw_review_for_skinResolver(source, args, context); + } + }, + send_feedback: { + description: "Send a message to the admin of the site. Currently this appears in Discord.", + name: "send_feedback", + type: GraphQLBoolean, + args: { + email: { + name: "email", + type: GraphQLString + }, + message: { + name: "message", + type: new GraphQLNonNull(GraphQLString) + }, + url: { + name: "url", + type: GraphQLString + } + }, + resolve(source, args, context) { + return mutationSend_feedbackResolver(source, args, context); + } + }, + upload: { + description: "Mutations for the upload flow", + name: "upload", + type: UploadMutationsType, + resolve(source) { + return mutationUploadResolver(source); + } + } + }; + } + }); + const ClassicSkinType: GraphQLObjectType = new GraphQLObjectType({ + name: "ClassicSkin", + description: "A classic Winamp skin", + fields() { + return { + archive_files: { + description: "List of files contained within the skin's .wsz archive", + name: "archive_files", + type: new GraphQLList(ArchiveFileType), + resolve(source) { + return classicSkinArchive_filesResolver(source); + } + }, + average_color: { + description: "String representation (rgb usually) of the skin's average color", + name: "average_color", + type: GraphQLString, + resolve(source) { + return classicSkinAverage_colorResolver(source); + } + }, + download_url: { + description: "URL to download the skin", + name: "download_url", + type: GraphQLString, + resolve(source) { + return classicSkinDownload_urlResolver(source); + } + }, + filename: { + description: "Filename of skin when uploaded to the Museum. Note: In some cases a skin\nhas been uploaded under multiple names. Here we just pick one.", + name: "filename", + type: GraphQLString, + args: { + normalize_extension: { + description: "If true, the the correct file extension (.wsz or .wal) will be .\nOtherwise, the original user-uploaded file extension will be used.", + name: "normalize_extension", + type: GraphQLBoolean, + defaultValue: false + } + }, + resolve(source, args) { + return classicSkinFilenameResolver(source, args); + } + }, + has_media_library: { + description: "Does the skin include sprite sheets for the media library?", + name: "has_media_library", + type: GraphQLBoolean + }, + id: { + description: "GraphQL ID of the skin", + name: "id", + type: new GraphQLNonNull(GraphQLID), + resolve(source) { + return classicSkinIdResolver(source); + } + }, + internet_archive_item: { + description: "The skin's \"item\" at archive.org", + name: "internet_archive_item", + type: InternetArchiveItemType, + resolve(source) { + return classicSkinInternet_archive_itemResolver(source); + } + }, + last_algolia_index_update_date: { + description: "The date on which this skin was last updated in the Algolia search index.\nGiven in simplified extended ISO format (ISO 8601).", + name: "last_algolia_index_update_date", + type: GraphQLString + }, + md5: { + description: "MD5 hash of the skin's file", + name: "md5", + type: GraphQLString, + resolve(source) { + return classicSkinMd5Resolver(source); + } + }, + museum_url: { + description: "URL of the skin on the Winamp Skin Museum", + name: "museum_url", + type: GraphQLString, + resolve(source) { + return classicSkinMuseum_urlResolver(source); + } + }, + nsfw: { + description: "Has the skin been flagged as \"not safe for work\"?\"", + name: "nsfw", + type: GraphQLBoolean, + resolve(source) { + return classicSkinNsfwResolver(source); + } + }, + readme_text: { + description: "Text of the readme file extracted from the skin", + name: "readme_text", + type: GraphQLString, + resolve(source) { + return classicSkinReadme_textResolver(source); + } + }, + reviews: { + description: "Times that the skin has been reviewed either on the Museum's Tinder-style\nreview page, or via the Discord bot.", + name: "reviews", + type: new GraphQLList(ReviewType), + resolve(source) { + return classicSkinReviewsResolver(source); + } + }, + screenshot_url: { + description: "URL of a screenshot of the skin", + name: "screenshot_url", + type: GraphQLString, + resolve(source) { + return classicSkinScreenshot_urlResolver(source); + } + }, + transparent_pixels: { + description: "The number of transparent pixels rendered by the skin.", + name: "transparent_pixels", + type: GraphQLInt + }, + tweeted: { + description: "Has the skin been tweeted?", + name: "tweeted", + type: GraphQLBoolean, + resolve(source) { + return classicSkinTweetedResolver(source); + } + }, + tweets: { + description: "List of", + name: "tweets", + type: new GraphQLList(TweetType), + resolve(source) { + return classicSkinTweetsResolver(source); + } + }, + webamp_url: { + description: "URL of webamp.org with the skin loaded", + name: "webamp_url", + type: GraphQLString, + resolve(source) { + return classicSkinWebamp_urlResolver(source); + } + } + }; + }, + interfaces() { + return [NodeType, SkinType]; + } + }); + return new GraphQLSchema({ + query: QueryType, + mutation: MutationType, + types: [RatingType, SkinUploadStatusType, SkinsFilterOptionType, SkinsSortOptionType, TweetsSortOptionType, NodeType, SkinType, UploadUrlRequestType, ArchiveFileType, ClassicSkinType, DatabaseStatisticsType, InternetArchiveItemType, ModernSkinType, ModernSkinsConnectionType, MutationType, QueryType, ReviewType, SkinUploadType, SkinsConnectionType, TweetType, TweetsConnectionType, UploadMutationsType, UploadUrlType, UserType] + }); +} diff --git a/packages/skin-database/package.json b/packages/skin-database/package.json index bf9a6224..34d46bcf 100644 --- a/packages/skin-database/package.json +++ b/packages/skin-database/package.json @@ -21,8 +21,7 @@ "express-graphql": "^0.12.0", "express-sitemap-xml": "^2.0.0", "fast-xml-parser": "^4.2.2", - "graphql": "14.7.0", - "grats": "0.0.0-main-b47472ff", + "graphql": "^16.8.1", "imagemin": "^7.0.0", "imagemin-optipng": "^7.0.0", "knex": "^0.21.1", @@ -50,13 +49,13 @@ "cli": "ts-node --transpile-only ./cli.ts", "sync": "ts-node --transpile-only ./tasks/syncWithArchive.ts", "migrate": "knex migrate:latest", - "grats": "grats --output=./api/graphql/schema.graphql" + "grats": "grats" }, "prettier": {}, "devDependencies": { "@babel/preset-typescript": "^7.10.1", - "@types/cookie-session": "^2.0.48", "@types/body-parser": "^1.19.5", + "@types/cookie-session": "^2.0.48", "@types/cors": "^2.8.17", "@types/express": "4.17.9", "@types/express-fileupload": "^1.4.4", @@ -66,10 +65,11 @@ "@types/supertest": "^2.0.10", "@typescript-eslint/eslint-plugin": "^7.1.0", "@typescript-eslint/parser": "^7.1.0", + "grats": "^0.0.23", "supertest": "^6.0.1", "typescript": "^5.3.3" }, "resolutions": { - "graphql": "15.3.0" + "graphql": "16.8.1" } } diff --git a/packages/skin-database/s3.js b/packages/skin-database/s3.js index 59355ca1..49c20f79 100644 --- a/packages/skin-database/s3.js +++ b/packages/skin-database/s3.js @@ -172,7 +172,6 @@ function putTemp(fileName, buffer) { ...acl, }, (err) => { - console.log("Hello..."); if (err) { rejectPromise(err); return; diff --git a/packages/skin-database/tsconfig.json b/packages/skin-database/tsconfig.json index 155e79e1..f37d0fd2 100644 --- a/packages/skin-database/tsconfig.json +++ b/packages/skin-database/tsconfig.json @@ -1,8 +1,11 @@ { "grats": { - "nullableByDefault": true + "nullableByDefault": true, + "graphqlSchema": "./api/graphql/schema.graphql", + "tsSchema": "./api/graphql/schema.ts" }, "compilerOptions": { + "plugins": [{ "name": "grats-ts-plugin" }], "module": "commonjs", "esModuleInterop": true, "target": "es6", diff --git a/yarn.lock b/yarn.lock index 71bec37b..66ab89da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3140,14 +3140,6 @@ dependencies: tslib "^2.4.0" -"@graphql-tools/utils@^9.2.1": - version "9.2.1" - resolved "https://registry.yarnpkg.com/@graphql-tools/utils/-/utils-9.2.1.tgz#1b3df0ef166cfa3eae706e3518b17d5922721c57" - integrity sha512-WUw506Ql6xzmOORlriNrD6Ugx+HjVgYxt9KCXD9mHAak+eaXSwuGGPyE60hy9xaDEoXKBsG7SkG69ybitaVl6A== - dependencies: - "@graphql-typed-document-node/core" "^3.1.1" - tslib "^2.4.0" - "@graphql-tools/wrap@9.2.1": version "9.2.1" resolved "https://registry.npmjs.org/@graphql-tools/wrap/-/wrap-9.2.1.tgz" @@ -3159,11 +3151,6 @@ tslib "^2.4.0" value-or-promise "1.0.11" -"@graphql-typed-document-node/core@^3.1.1": - version "3.2.0" - resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861" - integrity sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ== - "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.3.0": version "9.3.0" resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.3.0.tgz#8368869dcb735be2e7f5cb7647de78e167a251fb" @@ -15662,27 +15649,19 @@ graphql-ws@^5.4.1: resolved "https://registry.npmjs.org/graphql-ws/-/graphql-ws-5.11.1.tgz" integrity sha512-AlOO/Gt0fXuSHXe/Weo6o3rIQVnH5MW7ophzeYzL+vYNlkf0NbWRJ6IIFgtSLcv9JpTlQdxSpB3t0SnM47/BHA== -graphql@14.7.0: - version "14.7.0" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.7.0.tgz#7fa79a80a69be4a31c27dda824dc04dac2035a72" - integrity sha512-l0xWZpoPKpppFzMfvVyFmp9vLN7w/ZZJPefUicMCepfJeQ8sMcztloGYY9DfjVPo6tIUDzU5Hw3MUbIjj9AVVA== - dependencies: - iterall "^1.2.2" - -graphql@^16.6.0: +graphql@16.8.1, graphql@^16.6.0, graphql@^16.8.1: version "16.8.1" resolved "https://registry.yarnpkg.com/graphql/-/graphql-16.8.1.tgz#1930a965bef1170603702acdb68aedd3f3cf6f07" integrity sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw== -grats@0.0.0-main-b47472ff: - version "0.0.0-main-b47472ff" - resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.0-main-b47472ff.tgz#ca8d7f9bad66fcf7011090c681207105c4542f13" - integrity sha512-k+O8Jh3rqhCp80lZcYrXY5oWEf4FzwAtvLuTQtFskKPU8y6V/mlzL6per643uFSnisv7lmFrxY+8aBIbUDEFfg== +grats@^0.0.23: + version "0.0.23" + resolved "https://registry.yarnpkg.com/grats/-/grats-0.0.23.tgz#5fee4448c1b26b8f9ee0dfa3df49dba6f1353fd4" + integrity sha512-LqkHsw7OXXWkDAumMZ2AhV/SnDkrYgIEMhYm29ndSGmgFOP3PBfAZXgWcKrwKEU4FkWQ3JfN9PtpddwPN4t/Ig== dependencies: - "@graphql-tools/utils" "^9.2.1" commander "^10.0.0" graphql "^16.6.0" - typescript "^4.9.5" + typescript "^5.0.2" gulp-eslint@^3.0.1: version "3.0.1" @@ -17446,11 +17425,6 @@ isurl@^1.0.0-alpha5: has-to-string-tag-x "^1.2.0" is-object "^1.0.1" -iterall@^1.2.2: - version "1.3.0" - resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.3.0.tgz#afcb08492e2915cbd8a0884eb93a8c94d0d72fea" - integrity sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg== - jake@^10.8.5: version "10.8.5" resolved "https://registry.npmjs.org/jake/-/jake-10.8.5.tgz" @@ -27598,7 +27572,7 @@ typescript@^4.9.5: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== -typescript@^5.3.3: +typescript@^5.0.2, typescript@^5.3.3: version "5.3.3" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37" integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==