Upgrade caniuse-lite

This commit is contained in:
Jordan Eldredge 2022-04-01 23:37:23 -07:00
parent 093e93a739
commit 64908e8777
4 changed files with 117 additions and 217 deletions

View file

@ -1,7 +1,7 @@
import * as Utils from "./utils";
import { gql } from "./utils";
import TinderCard from "react-tinder-card";
import { API_URL, USE_GRAPHQL } from "./constants";
import { API_URL } from "./constants";
import React, { useState, useEffect } from "react";
function warmScreenshotImage(hash) {
@ -22,25 +22,11 @@ const mutation = gql`
`;
async function getSkinToReview() {
if (USE_GRAPHQL) {
const data = await Utils.fetchGraphql(mutation);
if (data.me.username) {
return data.skin_to_review;
} else {
window.location = `${API_URL}/auth`;
}
const data = await Utils.fetchGraphql(mutation);
if (data.me.username) {
return data.skin_to_review;
} else {
const response = await fetch(
`${API_URL}/to_review?cacheBust=${Math.random()}`,
{
mode: "cors",
credentials: "include",
}
);
if (response.status === 403) {
window.location = `${API_URL}/auth`;
}
return response.json();
window.location = `${API_URL}/auth`;
}
}
@ -74,54 +60,30 @@ function useQueuedSkin() {
}
async function approveSkin(md5) {
if (USE_GRAPHQL) {
const mutation = gql`
mutation ApproveSkin($md5: String!) {
approve_skin(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5 });
} else {
await restReview("approve", md5);
}
const mutation = gql`
mutation ApproveSkin($md5: String!) {
approve_skin(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5 });
}
async function rejectSkin(md5) {
if (USE_GRAPHQL) {
const mutation = gql`
mutation RejectSkin($md5: String!) {
reject_skin(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5 });
} else {
await restReview("reject", md5);
}
const mutation = gql`
mutation RejectSkin($md5: String!) {
reject_skin(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5 });
}
async function markSkinNSFW(md5) {
if (USE_GRAPHQL) {
const mutation = gql`
mutation markSkinNSFW($md5: String!) {
mark_skin_nsfw(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5 });
} else {
await restReview("nsfw", md5);
}
}
async function restReview(action, md5) {
const response = await fetch(`${API_URL}/skins/${md5}/${action}`, {
method: "POST",
mode: "cors",
credentials: "include",
});
if (response.status === 403) {
window.location = `${API_URL}/auth`;
}
const mutation = gql`
mutation markSkinNSFW($md5: String!) {
mark_skin_nsfw(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5 });
}
export default function ReviewPage() {

View file

@ -3,7 +3,6 @@ import { of, from, EMPTY, concat, timer, defer } from "rxjs";
import * as Actions from "./actionCreators";
import * as Selectors from "./selectors";
import * as Utils from "../utils";
import { USE_GRAPHQL } from "../constants";
import { gql } from "../utils";
import {
tap,
@ -198,43 +197,32 @@ const unloadedSkinEpic = (actions, states) =>
return { offset, first, chunk };
}),
mergeMap(({ offset, first, chunk }) => {
if (USE_GRAPHQL) {
const query = gql`
query MuseumPage($offset: Int, $first: Int) {
skins(offset: $offset, first: $first, sort: MUSEUM) {
count
nodes {
md5
filename
nsfw
}
const query = gql`
query MuseumPage($offset: Int, $first: Int) {
skins(offset: $offset, first: $first, sort: MUSEUM) {
count
nodes {
md5
filename
nsfw
}
}
`;
}
`;
return from(Utils.fetchGraphql(query, { offset, first })).pipe(
map((data) => {
// Map GraphQL data into the format previously returned by REST.
return {
skinCount: data.skins.count,
skins: data.skins.nodes.map((skin) => ({
md5: skin.md5,
fileName: skin.filename,
nsfw: skin.nsfw,
})),
};
}),
map((payload) => [payload, chunk])
);
}
return from(
fetch(
`${API_URL}/skins?offset=${chunk * CHUNK_SIZE}&first=${CHUNK_SIZE}`
)
).pipe(
mergeMap((response) => response.json()),
map((body) => [body, chunk])
return from(Utils.fetchGraphql(query, { offset, first })).pipe(
map((data) => {
// Map GraphQL data into the format previously returned by REST.
return {
skinCount: data.skins.count,
skins: data.skins.nodes.map((skin) => ({
md5: skin.md5,
fileName: skin.filename,
nsfw: skin.nsfw,
})),
};
}),
map((payload) => [payload, chunk])
);
}),
mergeMap(([body, chunk]) => {
@ -359,8 +347,8 @@ function uploadActions(file) {
);
}
const uploadFilesEpic = (actions, state) =>
actions.pipe(
const uploadFilesEpic = (actions, state) => {
return actions.pipe(
filter((action) => action.type === "TRY_TO_UPLOAD_FILE"),
mergeMap(({ id }) => {
const file = state.value.fileUploads[id];
@ -369,6 +357,7 @@ const uploadFilesEpic = (actions, state) =>
);
})
);
};
function getProcessingSkins(state) {
return Object.values(state.fileUploads).filter(
@ -506,37 +495,24 @@ const skinDataEpic = (actions, state) => {
skinData.fileName == null ||
skinData.nsfw == null
) {
if (USE_GRAPHQL) {
const QUERY = gql`
query IndividualSkin($md5: String!) {
fetch_skin_by_md5(md5: $md5) {
filename
nsfw
}
const QUERY = gql`
query IndividualSkin($md5: String!) {
fetch_skin_by_md5(md5: $md5) {
filename
nsfw
}
`;
return from(Utils.fetchGraphql(QUERY, { md5: hash })).pipe(
map((data) => {
const skin = data.fetch_skin_by_md5;
return Actions.gotSkinData(hash, {
md5: hash,
fileName: skin.filename,
nsfw: skin.nsfw,
});
})
);
} else {
return from(fetch(`${API_URL}/skins/${hash}`)).pipe(
switchMap((response) => response.json()),
map((body) => {
return Actions.gotSkinData(hash, {
md5: hash,
fileName: body.fileName,
nsfw: body.nsfw,
});
})
);
}
}
`;
return from(Utils.fetchGraphql(QUERY, { md5: hash })).pipe(
map((data) => {
const skin = data.fetch_skin_by_md5;
return Actions.gotSkinData(hash, {
md5: hash,
fileName: skin.filename,
nsfw: skin.nsfw,
});
})
);
}
return EMPTY;
})
@ -548,22 +524,12 @@ const markNsfwEpic = (actions) => {
filter((action) => action.type === "MARK_NSFW"),
mergeMap(async ({ hash }) => {
try {
if (USE_GRAPHQL) {
const mutation = gql`
mutation ReportSkin($md5: String!) {
request_nsfw_review_for_skin(md5: $md5)
}
`;
await Utils.fetchGraphql(mutation, { md5: hash });
} else {
const response = await fetch(`${API_URL}/skins/${hash}/report`, {
method: "POST",
mode: "cors",
});
if (!response.ok) {
throw new Error("Failed to report skin.");
const mutation = gql`
mutation ReportSkin($md5: String!) {
request_nsfw_review_for_skin(md5: $md5)
}
}
`;
await Utils.fetchGraphql(mutation, { md5: hash });
} catch (e) {
return Actions.alert(
"Oops. Something went wrong. Please try again later."

View file

@ -1,4 +1,3 @@
import { API_URL, USE_GRAPHQL } from "../constants";
import { gql, fetchGraphql } from "../utils";
// Upload a skin to S3 and then notify our API that it's ready to process.
@ -39,92 +38,65 @@ export async function upload(fileObj) {
// in the DB. For missing skins, we get a URL we can use to upload directly to
// S3.
export async function getUploadUrls(skins) {
if (USE_GRAPHQL) {
const files = Object.entries(skins).map(([md5, filename]) => {
return {
md5,
filename,
};
});
const mutation = gql`
mutation GetUploadUrls($files: [UploadUrlRequest!]!) {
upload {
get_upload_urls(files: $files) {
id
url
md5
}
const files = Object.entries(skins).map(([md5, filename]) => {
return {
md5,
filename,
};
});
const mutation = gql`
mutation GetUploadUrls($files: [UploadUrlRequest!]!) {
upload {
get_upload_urls(files: $files) {
id
url
md5
}
}
`;
const data = await fetchGraphql(mutation, { files });
const normalized = {};
for (const { id, url, md5 } of data.upload.get_upload_urls) {
normalized[md5] = {
id,
url,
};
}
return normalized;
} else {
const response = await fetch(`${API_URL}/skins/get_upload_urls`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ skins }),
});
return response.json();
`;
const data = await fetchGraphql(mutation, { files });
const normalized = {};
for (const { id, url, md5 } of data.upload.get_upload_urls) {
normalized[md5] = {
id,
url,
};
}
return normalized;
}
// Tell the server that we've uploaded a given skin to S3.
export async function reportUploaded(md5, id) {
if (USE_GRAPHQL) {
const mutation = gql`
mutation ReportUploaded($id: String!, $md5: String!) {
upload {
report_skin_uploaded(id: $id, md5: $md5)
}
const mutation = gql`
mutation ReportUploaded($id: String!, $md5: String!) {
upload {
report_skin_uploaded(id: $id, md5: $md5)
}
`;
const data = await fetchGraphql(mutation, { id, md5 });
if (!data.upload.report_skin_uploaded) {
throw new Error("Unable to report skin as uploaded.");
}
} else {
const url = new URL(`${API_URL}/skins/${md5}/uploaded`);
url.searchParams.append("id", id);
const response = await fetch(url, { method: "POST" });
if (!response.ok) {
throw new Error("Unable to report skin as uploaded.");
}
`;
const data = await fetchGraphql(mutation, { id, md5 });
if (!data.upload.report_skin_uploaded) {
throw new Error("Unable to report skin as uploaded.");
}
}
// Given a list of md5s, ask the server which ones have been fully screenshot etc.
export async function checkMd5sUploadStatus(md5s) {
if (USE_GRAPHQL) {
const query = gql`
query CheckUploadStatus($md5s: [String!]!) {
upload_statuses_by_md5(md5s: $md5s) {
upload_md5
status
}
const query = gql`
query CheckUploadStatus($md5s: [String!]!) {
upload_statuses_by_md5(md5s: $md5s) {
upload_md5
status
}
`;
const data = await fetchGraphql(query, { md5s });
const statusObj = {};
data.upload_statuses_by_md5.forEach((status) => {
statusObj[status.upload_md5] = status.status;
});
return statusObj;
} else {
const response = await fetch(`${API_URL}/skins/status`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ hashes: md5s }),
});
return response.json();
}
}
`;
const data = await fetchGraphql(query, { md5s });
const statusObj = {};
data.upload_statuses_by_md5.forEach((status) => {
statusObj[status.upload_md5] = status.status;
});
return statusObj;
}
export async function hashFile(file) {

View file

@ -3829,9 +3829,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30000989, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001036, caniuse-lite@^1.0.30001038:
version "1.0.30001157"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001157.tgz"
integrity sha512-gOerH9Wz2IRZ2ZPdMfBvyOi3cjaz4O4dgNwPGzx8EhqAs4+2IL/O+fJsbt+znSigujoZG8bVcIAUM/I/E5K3MA==
version "1.0.30001323"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001323.tgz"
integrity sha512-e4BF2RlCVELKx8+RmklSEIVub1TWrmdhvA5kEUueummz1XyySW0DVk+3x9HyhU9MuWTa2BhqLgEuEmUwASAdCA==
capture-exit@^2.0.0:
version "2.0.0"