mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-28 04:24:12 +00:00
Fix formatting
This commit is contained in:
parent
df5aa4f5db
commit
d7e4c1184b
9 changed files with 84 additions and 87 deletions
|
|
@ -31,19 +31,19 @@ export async function addSkinFromBuffer(
|
|||
const ctx = new UserContext();
|
||||
const md5 = md5Buffer(buffer);
|
||||
if (await SkinModel.exists(ctx, md5)) {
|
||||
console.log("Skin found.")
|
||||
console.log("Skin found.");
|
||||
return { md5, status: "FOUND" };
|
||||
}
|
||||
|
||||
// Note: This will thrown on invalid skins.
|
||||
console.log("Getting zip...")
|
||||
console.log("Getting zip...");
|
||||
const zip = await JSZip.loadAsync(buffer);
|
||||
console.log("Getting skin type...")
|
||||
console.log("Getting skin type...");
|
||||
const skinType = await getSkinType(zip);
|
||||
|
||||
switch (skinType) {
|
||||
case "CLASSIC":
|
||||
console.log("Adding classic skin...")
|
||||
console.log("Adding classic skin...");
|
||||
return addClassicSkinFromBuffer(ctx, buffer, md5, filePath, uploader);
|
||||
case "MODERN":
|
||||
return addModernSkinFromBuffer(ctx, buffer, md5, filePath, uploader);
|
||||
|
|
@ -57,13 +57,13 @@ async function addModernSkinFromBuffer(
|
|||
filePath: string,
|
||||
uploader: string
|
||||
): Promise<Result> {
|
||||
console.log("Write temporarty file.")
|
||||
console.log("Write temporarty file.");
|
||||
const tempFile = temp.path({ suffix: ".wal" });
|
||||
fs.writeFileSync(tempFile, buffer);
|
||||
console.log("Put skin to S3.")
|
||||
console.log("Put skin to S3.");
|
||||
await S3.putSkin(md5, buffer, "wal");
|
||||
|
||||
console.log("Add skin to DB")
|
||||
console.log("Add skin to DB");
|
||||
await Skins.addSkin({
|
||||
ctx,
|
||||
md5,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ async function graphQLRequest(query: string, variables?: any) {
|
|||
if (body.errors && body.errors.length) {
|
||||
for (const err of body.errors) {
|
||||
console.warn(err.message);
|
||||
console.warn('Stack', err.stack)
|
||||
console.warn("Stack", err.stack);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,35 +55,31 @@ async function graphQLRequest(query: string, variables?: any) {
|
|||
|
||||
test(".node", async () => {
|
||||
const { data } = await graphQLRequest(gql`
|
||||
query {
|
||||
skins(first: 1) {
|
||||
nodes {
|
||||
id
|
||||
query {
|
||||
skins(first: 1) {
|
||||
nodes {
|
||||
id
|
||||
md5
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
const skin = data.skins.nodes[0];
|
||||
expect(skin.id).toEqual("U2tpbl9fYV9mYWtlX21kNQ==");
|
||||
|
||||
const { data: data2 } = await graphQLRequest(
|
||||
gql`
|
||||
query MyQuery($id: ID!) {
|
||||
node(id: $id) {
|
||||
... on Skin {
|
||||
md5
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
const skin = data.skins.nodes[0];
|
||||
expect(skin.id).toEqual("U2tpbl9fYV9mYWtlX21kNQ==");
|
||||
|
||||
const { data: data2 } = await graphQLRequest(gql`
|
||||
query MyQuery($id: ID!) {
|
||||
node(id: $id) {
|
||||
... on Skin {
|
||||
md5
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
`, { id: skin.id });
|
||||
expect(
|
||||
|
||||
|
||||
|
||||
data2.node).toEqual({ md5: skin.md5 })
|
||||
`,
|
||||
{ id: skin.id }
|
||||
);
|
||||
expect(data2.node).toEqual({ md5: skin.md5 });
|
||||
});
|
||||
|
||||
describe(".me", () => {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ function getQueryNameFromDocument(document) {
|
|||
(def) => def.kind === "OperationDefinition"
|
||||
);
|
||||
if (!operationDefinition) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
return operationDefinition.name?.value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
export interface NodeResolver {
|
||||
id({ id }): Promise<string>
|
||||
__typename: String
|
||||
};
|
||||
id({ id }): Promise<string>;
|
||||
__typename: string;
|
||||
}
|
||||
|
||||
export function toId(graphqlType: string, id: string) {
|
||||
return Buffer.from(`${graphqlType}__${id}`).toString('base64')
|
||||
return Buffer.from(`${graphqlType}__${id}`).toString("base64");
|
||||
}
|
||||
|
||||
export function fromId(base64Id: string): { graphqlType: string, id: string } {
|
||||
const decoded = Buffer.from(base64Id, 'base64').toString('ascii')
|
||||
const [graphqlType, id] = decoded.split("__")
|
||||
return { graphqlType, id }
|
||||
export function fromId(base64Id: string): { graphqlType: string; id: string } {
|
||||
const decoded = Buffer.from(base64Id, "base64").toString("ascii");
|
||||
const [graphqlType, id] = decoded.split("__");
|
||||
return { graphqlType, id };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const index = client.initIndex("Skins");
|
|||
|
||||
class RootResolver extends MutationResolver {
|
||||
async node({ id }, { ctx }) {
|
||||
const { graphqlType, id: localId } = fromId(id)
|
||||
const { graphqlType, id: localId } = fromId(id);
|
||||
// TODO Use typeResolver
|
||||
switch (graphqlType) {
|
||||
case "Skin": {
|
||||
|
|
@ -128,7 +128,7 @@ class RootResolver extends MutationResolver {
|
|||
const skinModel = await SkinModel.fromMd5(ctx, skin_md5);
|
||||
const skin = skinModel == null ? null : new SkinResolver(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
|
||||
// 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 };
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ export default class SkinResolver implements NodeResolver {
|
|||
}
|
||||
__typename = "Skin";
|
||||
async id() {
|
||||
return toId("Skin", this.md5())
|
||||
return toId("Skin", this.md5());
|
||||
}
|
||||
md5() {
|
||||
return this._model.getMd5();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import { program } from "commander";
|
|||
import * as config from "./config";
|
||||
import { setHashesForSkin } from "./skinHash";
|
||||
|
||||
|
||||
async function withHandler(
|
||||
cb: (handler: DiscordEventHandler) => Promise<void>
|
||||
) {
|
||||
|
|
@ -73,7 +72,7 @@ program
|
|||
.command("share")
|
||||
.description(
|
||||
"Share a skin on Twitter and Instagram. If no md5 is " +
|
||||
"given, random approved skins are shared."
|
||||
"given, random approved skins are shared."
|
||||
)
|
||||
.argument("[md5]", "md5 of the skin to share")
|
||||
.option("-t, --twitter", "Share on Twitter")
|
||||
|
|
@ -102,12 +101,12 @@ program
|
|||
.option(
|
||||
"--delete",
|
||||
"Delete a skin from the database, including its S3 files " +
|
||||
"CloudFlare cache and seach index entries."
|
||||
"CloudFlare cache and seach index entries."
|
||||
)
|
||||
.option(
|
||||
"--delete-local",
|
||||
"Delete a skin from the database only, NOT including its S3 files " +
|
||||
"CloudFlare cache and seach index entries."
|
||||
"CloudFlare cache and seach index entries."
|
||||
)
|
||||
.option("--index", "Update the seach index for a skin.")
|
||||
.option(
|
||||
|
|
@ -116,30 +115,35 @@ program
|
|||
)
|
||||
.option("--reject", 'Give a skin a "rejected" review.')
|
||||
.option("--metadata", "Push metadata to the archive.")
|
||||
.action(async (md5, { delete: del, deleteLocal, index, refresh, reject, metadata }) => {
|
||||
const ctx = new UserContext("CLI");
|
||||
if (del) {
|
||||
await Skins.deleteSkin(md5);
|
||||
.action(
|
||||
async (
|
||||
md5,
|
||||
{ delete: del, deleteLocal, index, refresh, reject, metadata }
|
||||
) => {
|
||||
const ctx = new UserContext("CLI");
|
||||
if (del) {
|
||||
await Skins.deleteSkin(md5);
|
||||
}
|
||||
if (deleteLocal) {
|
||||
await Skins.deleteLocalSkin(md5);
|
||||
}
|
||||
if (index) {
|
||||
console.log(await Skins.updateSearchIndex(ctx, md5));
|
||||
}
|
||||
if (refresh) {
|
||||
const skin = await SkinModel.fromMd5Assert(ctx, md5);
|
||||
await refreshSkins([skin], { noScreenshot: true });
|
||||
}
|
||||
if (reject) {
|
||||
await Skins.reject(ctx, md5);
|
||||
}
|
||||
if (metadata) {
|
||||
const skin = await SkinModel.fromMd5Assert(ctx, md5);
|
||||
await SyncToArchive.updateMetadata(skin);
|
||||
console.log("Updated Metadata");
|
||||
}
|
||||
}
|
||||
if (deleteLocal) {
|
||||
await Skins.deleteLocalSkin(md5);
|
||||
}
|
||||
if (index) {
|
||||
console.log(await Skins.updateSearchIndex(ctx, md5));
|
||||
}
|
||||
if (refresh) {
|
||||
const skin = await SkinModel.fromMd5Assert(ctx, md5);
|
||||
await refreshSkins([skin], { noScreenshot: true });
|
||||
}
|
||||
if (reject) {
|
||||
await Skins.reject(ctx, md5);
|
||||
}
|
||||
if (metadata) {
|
||||
const skin = await SkinModel.fromMd5Assert(ctx, md5);
|
||||
await SyncToArchive.updateMetadata(skin);
|
||||
console.log("Updated Metadata");
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
program
|
||||
.command("file")
|
||||
|
|
@ -178,18 +182,18 @@ program
|
|||
.option(
|
||||
"--fetch-metadata <count>",
|
||||
"Fetch missing metadata for <count> items from the Internet " +
|
||||
"Archive. Currently it only fetches missing metadata. In the " +
|
||||
"future it could refresh stale metadata."
|
||||
"Archive. Currently it only fetches missing metadata. In the " +
|
||||
"future it could refresh stale metadata."
|
||||
)
|
||||
.option(
|
||||
"--fetch-items",
|
||||
"Seach the Internet Archive for items that we don't know about" +
|
||||
"and add them to our database."
|
||||
"and add them to our database."
|
||||
)
|
||||
.option(
|
||||
"--update-metadata <count>",
|
||||
"Find <count> items in our database that have incorrect or incomplete " +
|
||||
"metadata, and update the Internet Archive"
|
||||
"metadata, and update the Internet Archive"
|
||||
)
|
||||
.option(
|
||||
"--upload-new",
|
||||
|
|
@ -223,7 +227,7 @@ program
|
|||
.command("stats")
|
||||
.description(
|
||||
"Report information about skins in the database. " +
|
||||
"Identical to `!stats` in Discord."
|
||||
"Identical to `!stats` in Discord."
|
||||
)
|
||||
.action(async () => {
|
||||
console.table([await Skins.getStats()]);
|
||||
|
|
@ -269,17 +273,17 @@ program
|
|||
.option(
|
||||
"--likes",
|
||||
"Scrape @winampskins tweets for like and retweet counts, " +
|
||||
"and update the database."
|
||||
"and update the database."
|
||||
)
|
||||
.option(
|
||||
"--milestones",
|
||||
"Check the most recent @winampskins tweets to see if they have " +
|
||||
"passed a milestone. If so, notify the Discord channel."
|
||||
"passed a milestone. If so, notify the Discord channel."
|
||||
)
|
||||
.option(
|
||||
"--followers",
|
||||
"Check if @winampskins has passed a follower count milestone. " +
|
||||
"If so, notify the Discord channel."
|
||||
"If so, notify the Discord channel."
|
||||
)
|
||||
.action(async ({ likes, milestones, followers }) => {
|
||||
if (likes) {
|
||||
|
|
@ -307,7 +311,7 @@ program
|
|||
.option(
|
||||
"--upload-ia-screenshot <md5>",
|
||||
"Upload a screenshot of a skin to the skin's Internet Archive itme. " +
|
||||
"[[Warning!]] This might result in multiple screenshots on the item."
|
||||
"[[Warning!]] This might result in multiple screenshots on the item."
|
||||
)
|
||||
.option(
|
||||
"--upload-missing-screenshots",
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export const IS_NOT_README =
|
|||
/(genex\.txt)|(genexinfo\.txt)|(gen_gslyrics\.txt)|(region\.txt)|(pledit\.txt)|(viscolor\.txt)|(winampmb\.txt)|("gen_ex help\.txt)|(mbinner\.txt)$/i;
|
||||
|
||||
export default class SkinModel {
|
||||
constructor(readonly ctx: UserContext, readonly row: SkinRow) { }
|
||||
constructor(readonly ctx: UserContext, readonly row: SkinRow) {}
|
||||
|
||||
static async fromMd5(
|
||||
ctx: UserContext,
|
||||
|
|
@ -37,10 +37,7 @@ export default class SkinModel {
|
|||
return row == null ? null : new SkinModel(ctx, row);
|
||||
}
|
||||
|
||||
static clearMd5(
|
||||
ctx: UserContext,
|
||||
md5: string
|
||||
): void {
|
||||
static clearMd5(ctx: UserContext, md5: string): void {
|
||||
getSkinLoader(ctx).clear(md5);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ export async function addSkin({
|
|||
uploader,
|
||||
modern,
|
||||
}: {
|
||||
ctx: UserContext,
|
||||
ctx: UserContext;
|
||||
md5: string;
|
||||
filePath: string;
|
||||
uploader: string;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue