mirror of
https://github.com/chaoticbackup/chaoticbackup.github.io.git
synced 2026-03-21 17:24:14 -05:00
update for v4 sheet api
This commit is contained in:
parent
1359d840dc
commit
c96d2a49f6
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
99
package-lock.json
generated
99
package-lock.json
generated
|
|
@ -3405,11 +3405,6 @@
|
|||
"@types/react": "*"
|
||||
}
|
||||
},
|
||||
"@types/retry": {
|
||||
"version": "0.12.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.1.tgz",
|
||||
"integrity": "sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g=="
|
||||
},
|
||||
"@types/scheduler": {
|
||||
"version": "0.16.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz",
|
||||
|
|
@ -3486,13 +3481,13 @@
|
|||
}
|
||||
},
|
||||
"@typescript-eslint/eslint-plugin": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.1.tgz",
|
||||
"integrity": "sha512-AHqIU+SqZZgBEiWOrtN94ldR3ZUABV5dUG94j8Nms9rQnHFc8fvDOue/58K4CFz6r8OtDDc35Pw9NQPWo0Ayrw==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.29.2.tgz",
|
||||
"integrity": "sha512-x4EMgn4BTfVd9+Z+r+6rmWxoAzBaapt4QFqE+d8L8sUtYZYLDTK6VG/y/SMMWA5t1/BVU5Kf+20rX4PtWzUYZg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/experimental-utils": "4.29.1",
|
||||
"@typescript-eslint/scope-manager": "4.29.1",
|
||||
"@typescript-eslint/experimental-utils": "4.29.2",
|
||||
"@typescript-eslint/scope-manager": "4.29.2",
|
||||
"debug": "^4.3.1",
|
||||
"functional-red-black-tree": "^1.0.1",
|
||||
"regexpp": "^3.1.0",
|
||||
|
|
@ -3527,28 +3522,28 @@
|
|||
}
|
||||
},
|
||||
"@typescript-eslint/experimental-utils": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.29.1.tgz",
|
||||
"integrity": "sha512-kl6QG6qpzZthfd2bzPNSJB2YcZpNOrP6r9jueXupcZHnL74WiuSjaft7WSu17J9+ae9zTlk0KJMXPUj0daBxMw==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-4.29.2.tgz",
|
||||
"integrity": "sha512-P6mn4pqObhftBBPAv4GQtEK7Yos1fz/MlpT7+YjH9fTxZcALbiiPKuSIfYP/j13CeOjfq8/fr9Thr2glM9ub7A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/json-schema": "^7.0.7",
|
||||
"@typescript-eslint/scope-manager": "4.29.1",
|
||||
"@typescript-eslint/types": "4.29.1",
|
||||
"@typescript-eslint/typescript-estree": "4.29.1",
|
||||
"@typescript-eslint/scope-manager": "4.29.2",
|
||||
"@typescript-eslint/types": "4.29.2",
|
||||
"@typescript-eslint/typescript-estree": "4.29.2",
|
||||
"eslint-scope": "^5.1.1",
|
||||
"eslint-utils": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/parser": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.29.1.tgz",
|
||||
"integrity": "sha512-3fL5iN20hzX3Q4OkG7QEPFjZV2qsVGiDhEwwh+EkmE/w7oteiOvUNzmpu5eSwGJX/anCryONltJ3WDmAzAoCMg==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.29.2.tgz",
|
||||
"integrity": "sha512-WQ6BPf+lNuwteUuyk1jD/aHKqMQ9jrdCn7Gxt9vvBnzbpj7aWEf+aZsJ1zvTjx5zFxGCt000lsbD9tQPEL8u6g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/scope-manager": "4.29.1",
|
||||
"@typescript-eslint/types": "4.29.1",
|
||||
"@typescript-eslint/typescript-estree": "4.29.1",
|
||||
"@typescript-eslint/scope-manager": "4.29.2",
|
||||
"@typescript-eslint/types": "4.29.2",
|
||||
"@typescript-eslint/typescript-estree": "4.29.2",
|
||||
"debug": "^4.3.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -3570,29 +3565,29 @@
|
|||
}
|
||||
},
|
||||
"@typescript-eslint/scope-manager": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.29.1.tgz",
|
||||
"integrity": "sha512-Hzv/uZOa9zrD/W5mftZa54Jd5Fed3tL6b4HeaOpwVSabJK8CJ+2MkDasnX/XK4rqP5ZTWngK1ZDeCi6EnxPQ7A==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.29.2.tgz",
|
||||
"integrity": "sha512-mfHmvlQxmfkU8D55CkZO2sQOueTxLqGvzV+mG6S/6fIunDiD2ouwsAoiYCZYDDK73QCibYjIZmGhpvKwAB5BOA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "4.29.1",
|
||||
"@typescript-eslint/visitor-keys": "4.29.1"
|
||||
"@typescript-eslint/types": "4.29.2",
|
||||
"@typescript-eslint/visitor-keys": "4.29.2"
|
||||
}
|
||||
},
|
||||
"@typescript-eslint/types": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.29.1.tgz",
|
||||
"integrity": "sha512-Jj2yu78IRfw4nlaLtKjVaGaxh/6FhofmQ/j8v3NXmAiKafbIqtAPnKYrf0sbGjKdj0hS316J8WhnGnErbJ4RCA==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.29.2.tgz",
|
||||
"integrity": "sha512-K6ApnEXId+WTGxqnda8z4LhNMa/pZmbTFkDxEBLQAbhLZL50DjeY0VIDCml/0Y3FlcbqXZrABqrcKxq+n0LwzQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@typescript-eslint/typescript-estree": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.29.1.tgz",
|
||||
"integrity": "sha512-lIkkrR9E4lwZkzPiRDNq0xdC3f2iVCUjw/7WPJ4S2Sl6C3nRWkeE1YXCQ0+KsiaQRbpY16jNaokdWnm9aUIsfw==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.29.2.tgz",
|
||||
"integrity": "sha512-TJ0/hEnYxapYn9SGn3dCnETO0r+MjaxtlWZ2xU+EvytF0g4CqTpZL48SqSNn2hXsPolnewF30pdzR9a5Lj3DNg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "4.29.1",
|
||||
"@typescript-eslint/visitor-keys": "4.29.1",
|
||||
"@typescript-eslint/types": "4.29.2",
|
||||
"@typescript-eslint/visitor-keys": "4.29.2",
|
||||
"debug": "^4.3.1",
|
||||
"globby": "^11.0.3",
|
||||
"is-glob": "^4.0.1",
|
||||
|
|
@ -3627,12 +3622,12 @@
|
|||
}
|
||||
},
|
||||
"@typescript-eslint/visitor-keys": {
|
||||
"version": "4.29.1",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.29.1.tgz",
|
||||
"integrity": "sha512-zLqtjMoXvgdZY/PG6gqA73V8BjqPs4af1v2kiiETBObp+uC6gRYnJLmJHxC0QyUrrHDLJPIWNYxoBV3wbcRlag==",
|
||||
"version": "4.29.2",
|
||||
"resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.29.2.tgz",
|
||||
"integrity": "sha512-bDgJLQ86oWHJoZ1ai4TZdgXzJxsea3Ee9u9wsTAvjChdj2WLcVsgWYAPeY7RQMn16tKrlQaBnpKv7KBfs4EQag==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@typescript-eslint/types": "4.29.1",
|
||||
"@typescript-eslint/types": "4.29.2",
|
||||
"eslint-visitor-keys": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -10178,15 +10173,6 @@
|
|||
"p-limit": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"p-retry": {
|
||||
"version": "4.6.1",
|
||||
"resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.6.1.tgz",
|
||||
"integrity": "sha512-e2xXGNhZOZ0lfgR9kL34iGlU8N/KO0xZnQxVEwdeOvpqNDQfdnxIYizvWtK8RglUa3bGqI8g0R/BdfzLMxRkiA==",
|
||||
"requires": {
|
||||
"@types/retry": "^0.12.0",
|
||||
"retry": "^0.13.1"
|
||||
}
|
||||
},
|
||||
"p-try": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
|
||||
|
|
@ -11340,11 +11326,6 @@
|
|||
"integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==",
|
||||
"dev": true
|
||||
},
|
||||
"retry": {
|
||||
"version": "0.13.1",
|
||||
"resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz",
|
||||
"integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg=="
|
||||
},
|
||||
"reusify": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
|
||||
|
|
@ -11403,9 +11384,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"sass": {
|
||||
"version": "1.37.5",
|
||||
"resolved": "https://registry.npmjs.org/sass/-/sass-1.37.5.tgz",
|
||||
"integrity": "sha512-Cx3ewxz9QB/ErnVIiWg2cH0kiYZ0FPvheDTVC6BsiEGBTZKKZJ1Gq5Kq6jy3PKtL6+EJ8NIoaBW/RSd2R6cZOA==",
|
||||
"version": "1.38.0",
|
||||
"resolved": "https://registry.npmjs.org/sass/-/sass-1.38.0.tgz",
|
||||
"integrity": "sha512-WBccZeMigAGKoI+NgD7Adh0ab1HUq+6BmyBUEaGxtErbUtWUevEbdgo5EZiJQofLUGcKtlNaO2IdN73AHEua5g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"chokidar": ">=3.0.0 <4.0.0"
|
||||
|
|
@ -12582,9 +12563,9 @@
|
|||
}
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "10.2.0",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.0.tgz",
|
||||
"integrity": "sha512-FstYHtQz6isj8rBtYMN4bZdnXN1vq4HCbqn9vdNQcInRqtB86PePJQIxE6es0PhxKWhj2PHuwbG40H+bxkZPmg==",
|
||||
"version": "10.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.1.tgz",
|
||||
"integrity": "sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@cspotcode/source-map-support": "0.6.1",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
"lokijs": "^1.5.12",
|
||||
"mobx": "^5.15.7",
|
||||
"mobx-react": "^6.3.1",
|
||||
"p-retry": "^4.6.1",
|
||||
"prop-types": "^15.7.2",
|
||||
"react": "^16.14.0",
|
||||
"react-collapsible": "^2.8.3",
|
||||
|
|
@ -61,8 +60,8 @@
|
|||
"@types/react": "^16.14.13",
|
||||
"@types/react-dom": "^16.9.14",
|
||||
"@types/react-router-dom": "^5.1.8",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.1",
|
||||
"@typescript-eslint/parser": "^4.29.1",
|
||||
"@typescript-eslint/eslint-plugin": "^4.29.2",
|
||||
"@typescript-eslint/parser": "^4.29.2",
|
||||
"babel-eslint": "^10.1.0",
|
||||
"babel-loader": "^8.2.2",
|
||||
"chai": "^4.3.4",
|
||||
|
|
@ -83,11 +82,11 @@
|
|||
"mini-css-extract-plugin": "^2.2.0",
|
||||
"mocha": "^8.4.0",
|
||||
"postcss": "^8.3.6",
|
||||
"sass": "^1.37.5",
|
||||
"sass": "^1.38.0",
|
||||
"sass-loader": "^12.1.0",
|
||||
"style-loader": "^3.2.1",
|
||||
"terser-webpack-plugin": "^5.1.4",
|
||||
"ts-node": "^10.2.0",
|
||||
"ts-node": "^10.2.1",
|
||||
"typescript": "^4.3.5",
|
||||
"webpack": "^5.50.0",
|
||||
"webpack-cli": "^4.8.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import 'whatwg-fetch';
|
||||
import { observable } from "mobx";
|
||||
import pRetry from 'p-retry';
|
||||
import CollectionDB from './CollectionDB';
|
||||
import spreadsheet_data from './meta_spreadsheet.json';
|
||||
import { Card } from '../common/definitions';
|
||||
|
|
@ -9,32 +8,38 @@ type card_type = 'attacks' | 'battlegear' | 'creatures' | 'locations' | 'mugic';
|
|||
|
||||
type data_type = 'cards' | 'portal';
|
||||
|
||||
function retry (fn: () => any, retries=0, err=null) {
|
||||
if (retries < 0) {
|
||||
return Promise.reject(err);
|
||||
}
|
||||
return fn().catch((err: any) => {
|
||||
return retry(fn, (retries - 1), err);
|
||||
});
|
||||
}
|
||||
|
||||
class API {
|
||||
@observable portal;
|
||||
@observable cards;
|
||||
@observable urls;
|
||||
private static instance: API;
|
||||
|
||||
static base_url = "https://spreadsheets.google.com/feeds/list/";
|
||||
static data_format = "/od6/public/values?alt=json";
|
||||
// + "/od6/public/basic?alt=json"; // Alternate data format
|
||||
get base_image() { return "https://drive.google.com/uc?id=" }
|
||||
get thumb_missing() { return "1JYjPzkv74IhzlHTyVh2niTDyui73HSfp" }
|
||||
get card_back() { return "https://i.imgur.com/xbeDBRJ.png" }
|
||||
// such secure, much wow
|
||||
get key() {
|
||||
return ["AIz", "aSy", "Bfq", "09-", "tBi", "78b", "nH6", "6f1", "Lkn", "zGD", "XM9", "Zu9", "JG0"].join("");
|
||||
}
|
||||
|
||||
private constructor () {
|
||||
// This sets up urls and kicks off db
|
||||
// let base_spreadsheet = "1cUNmwV693zl2zqbH_IG4Wz8o9Va_sOHe7pAZF6M59Es";
|
||||
try {
|
||||
const urls = {};
|
||||
// this.getSpreadsheet(API.path(API.base_spreadsheet), (data) => {
|
||||
// if (data == null) throw "no data from base_spreadsheet";
|
||||
spreadsheet_data.forEach((d) => {
|
||||
if (!urls[d.gsx$type.$t]) urls[d.gsx$type.$t] = {};
|
||||
urls[d.gsx$type.$t][d.gsx$subtype.$t] = this.path(d.gsx$url.$t);
|
||||
spreadsheet_data.forEach(({ type, subtype, url }) => {
|
||||
if (!urls[type]) urls[type] = {};
|
||||
urls[type][subtype] = url;
|
||||
});
|
||||
this.urls = urls;
|
||||
// });
|
||||
|
||||
this.portal = new CollectionDB(this, 'portal');
|
||||
this.cards = new CollectionDB(this, 'cards');
|
||||
|
|
@ -53,25 +58,63 @@ class API {
|
|||
return API.instance;
|
||||
}
|
||||
|
||||
// Wrapper
|
||||
path(spreadsheetID: string) {
|
||||
return API.base_url + spreadsheetID + API.data_format;
|
||||
return `https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetID}/values/Sheet1?key=${this.key}`;
|
||||
}
|
||||
|
||||
async getSpreadsheetTime(spreadsheetId: string) {
|
||||
const url = `https://content.googleapis.com/drive/v3/files/${spreadsheetId}?fields=modifiedTime&key=${this.key}`;
|
||||
const response = await fetch(url);
|
||||
|
||||
if (response.status === 200) {
|
||||
const json = await response.json();
|
||||
if ("modifiedTime" in json) {
|
||||
return Promise.resolve(json.modifiedTime);
|
||||
}
|
||||
}
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
async getSpreadsheetData(spreadsheetId: string, doRetry: boolean = false) {
|
||||
const url = this.path(spreadsheetId);
|
||||
|
||||
const cmd = async () => {
|
||||
const response = await fetch(url);
|
||||
|
||||
if (response.status === 404) {
|
||||
throw new Error("Can't Open File");
|
||||
}
|
||||
|
||||
try {
|
||||
const json = await response.json();
|
||||
return json.values;
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
};
|
||||
|
||||
return retry(cmd, doRetry ? 3 : 0);
|
||||
}
|
||||
|
||||
async getSpreadsheet(spreadsheet: string, retry: boolean, callback: (data: any) => any) {
|
||||
await pRetry(async () => {
|
||||
return fetch(spreadsheet)
|
||||
.then((response) => {
|
||||
if (response.status === 404) throw new Error("Can't Open File");
|
||||
return response.json();
|
||||
})
|
||||
.then((json) => {
|
||||
callback(json.feed.entry);
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new pRetry.AbortError(err);
|
||||
// Wrapper that transforms spreadsheet data into expected object
|
||||
async parseSpreadsheetData(spreadsheetId: string, cardType: string, doRetry: boolean = false) {
|
||||
return this.getSpreadsheetData(spreadsheetId, doRetry)
|
||||
.then((data: Array<Array<string>>) => {
|
||||
if (data.length < 2) return [];
|
||||
|
||||
const header = data.shift()!.map((h: string) => h.toLowerCase().replace(" ", ""));
|
||||
const cards = data.map((card: string[]) => {
|
||||
const obj = { "gsx$type": cardType };
|
||||
|
||||
for (let i = 0; i < header.length; i++) {
|
||||
obj[`gsx$${header[i]}`] = card[i];
|
||||
}
|
||||
|
||||
return obj;
|
||||
});
|
||||
}, { retries: retry ? 3 : 0 });
|
||||
|
||||
return cards;
|
||||
});
|
||||
}
|
||||
|
||||
// Input format
|
||||
|
|
@ -81,10 +124,10 @@ class API {
|
|||
return Promise.all(input.map((item) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if ('cards' in item) {
|
||||
return this.cards!.setupType(item.cards, resolve);
|
||||
return this.cards!.setupType(item.cards, resolve, reject);
|
||||
}
|
||||
else if ('portal' in item) {
|
||||
return this.portal!.setupType(item.portal, resolve);
|
||||
return this.portal!.setupType(item.portal, resolve, reject);
|
||||
}
|
||||
else {
|
||||
console.error('key must be cards or portal');
|
||||
|
|
@ -137,7 +180,9 @@ class API {
|
|||
purgeDB() {
|
||||
if (this.cards) this.cards.purgeDB();
|
||||
if (this.portal) this.portal.purgeDB();
|
||||
window.location.reload();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 300);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import loki from 'lokijs';
|
||||
import Loki from 'lokijs';
|
||||
import { observable, observe, action } from "mobx";
|
||||
import Cookies from 'universal-cookie';
|
||||
const cookies = new Cookies();
|
||||
|
|
@ -12,60 +12,64 @@ class CollectionDB {
|
|||
this.format = format;
|
||||
this.setupDB(format);
|
||||
}
|
||||
|
||||
// Wrapper that transforms spreadsheet data into expected object
|
||||
async getSpreadsheetData(spreadsheet, type, retry, callback) {
|
||||
this.api.getSpreadsheet(spreadsheet, retry, (data) => {
|
||||
callback(data.map((item) => {
|
||||
const temp = {};
|
||||
delete item.content;
|
||||
for (const key of Object.keys(item)) {
|
||||
temp[key] = item[key].$t;
|
||||
}
|
||||
temp["gsx$type"] = type;
|
||||
return temp;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// example format
|
||||
// this.setup(this.api.urls.Attacks["portal"], "Attack", (data) => {});
|
||||
@action
|
||||
async setupType(type, resolve) {
|
||||
async setupType(type, resolve, reject) {
|
||||
if (this.building.hasOwnProperty(type)) {
|
||||
const uc_type = type.charAt(0).toUpperCase() + type.slice(1);
|
||||
if (this.building[type].get() == "built") {
|
||||
const building = this.building[type].get();
|
||||
|
||||
if (building == "built") {
|
||||
// Check if data has been updated
|
||||
this.getSpreadsheetData(this.api.urls[uc_type][this.format], uc_type, false, (data) => {
|
||||
return this.api.getSpreadsheetTime(this.api.urls[uc_type][this.format])
|
||||
.then((modifiedTime) => {
|
||||
const cookie = cookies.get(`${this.format}_${type}`);
|
||||
if (cookie) {
|
||||
if ((new Date(data[0].updated)) > (new Date(cookie))) {
|
||||
if ((new Date(modifiedTime)) > (new Date(cookie))) {
|
||||
this[type].clear();
|
||||
this[type].insert(data);
|
||||
cookies.set(`${this.format}_${type}`, data[0].updated, { path: '/' });
|
||||
this.building[type].set("setup");
|
||||
return this.setupType(type, resolve, reject);
|
||||
}
|
||||
else {
|
||||
return resolve();
|
||||
}
|
||||
}
|
||||
else {
|
||||
cookies.set(`${this.format}_${type}`, data[0].updated, { path: '/' });
|
||||
cookies.set(`${this.format}_${type}`, modifiedTime, { path: '/' });
|
||||
return resolve();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
return resolve();
|
||||
});
|
||||
return resolve();
|
||||
}
|
||||
if (this.building[type].get() == "building") {
|
||||
else if (building == "building") {
|
||||
const disposer = observe(this.building[type], (change) => {
|
||||
disposer();
|
||||
resolve();
|
||||
});
|
||||
return disposer;
|
||||
}
|
||||
if (this.building[type].get() == "setup") {
|
||||
this.building[type].set("building");
|
||||
else if (building == "setup") {
|
||||
// check if the collection already exists in memory
|
||||
if (this[type].data.length == 0) {
|
||||
return this.getSpreadsheetData(this.api.urls[uc_type][this.format], uc_type, true, (data) => {
|
||||
this.building[type].set("building");
|
||||
return this.api.parseSpreadsheetData(this.api.urls[uc_type][this.format], uc_type, true)
|
||||
.then(async (data) => {
|
||||
this[type].insert(data);
|
||||
this.building[type].set("built");
|
||||
|
||||
try {
|
||||
const modifiedTime = await this.api.getSpreadsheetTime(this.api.urls[uc_type][this.format]);
|
||||
cookies.set(`${this.format}_${type}`, modifiedTime, { path: '/' });
|
||||
} catch (err) {/* */}
|
||||
|
||||
return resolve();
|
||||
})
|
||||
.catch(() => {
|
||||
return reject();
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
|
@ -87,7 +91,28 @@ class CollectionDB {
|
|||
|
||||
@action
|
||||
setupDB(format) {
|
||||
const db = new loki(`chaotic_${format}.db`, {
|
||||
function databaseInitialize() {
|
||||
["attacks", "battlegear", "creatures", "locations", "mugic"].forEach((type) => {
|
||||
// check if the db already exists in memory
|
||||
const entries = db.getCollection(type);
|
||||
if (entries === null || entries.data.length === 0) {
|
||||
this[type] = db.addCollection(type);
|
||||
if (this.building[type])
|
||||
this.building[type].set("setup");
|
||||
else
|
||||
this.building[type] = observable.box("setup");
|
||||
}
|
||||
else {
|
||||
this[type] = entries;
|
||||
if (this.building[type])
|
||||
this.building[type].set("built");
|
||||
else
|
||||
this.building[type] = observable.box("built");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const db = new Loki(`chaotic_${format}.db`, {
|
||||
autosave: true,
|
||||
autoload: true,
|
||||
autoloadCallback: databaseInitialize.bind(this),
|
||||
|
|
@ -96,32 +121,13 @@ class CollectionDB {
|
|||
});
|
||||
|
||||
this.db = db;
|
||||
|
||||
function databaseInitialize() {
|
||||
["attacks","battlegear", "creatures", "locations", "mugic"]
|
||||
.forEach((type) => {
|
||||
// check if the db already exists in memory
|
||||
const entries = db.getCollection(type);
|
||||
if (entries === null || entries.data.length === 0) {
|
||||
this[type] = db.addCollection(type);
|
||||
if (this.building[type])
|
||||
this.building[type].set("setup");
|
||||
else
|
||||
this.building[type] = observable.box("setup");
|
||||
}
|
||||
else {
|
||||
this[type] = entries;
|
||||
if (this.building[type])
|
||||
this.building[type].set("built");
|
||||
else
|
||||
this.building[type] = observable.box("built");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
purgeDB = () => {
|
||||
this.db.deleteDatabase();
|
||||
["attacks", "battlegear", "creatures", "locations", "mugic"].forEach((type) => {
|
||||
this.db.removeCollection(type);
|
||||
});
|
||||
this.db.saveDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,52 +1,52 @@
|
|||
[
|
||||
{
|
||||
"gsx$type": {"$t": "Creatures"},
|
||||
"gsx$subtype": {"$t": "cards"},
|
||||
"gsx$url": {"$t": "1fUFYhG1NLLkSTzrdbevm6ZMKNP6xLiKUZvM1sY10pVI"}
|
||||
"type": "Creatures",
|
||||
"subtype": "cards",
|
||||
"url": "1fUFYhG1NLLkSTzrdbevm6ZMKNP6xLiKUZvM1sY10pVI"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Creatures"},
|
||||
"gsx$subtype": {"$t": "portal"},
|
||||
"gsx$url": {"$t": "1eGQsy2kYk7HfnQetsjobMqank4bg6iWOOaSYykg3Yec"}
|
||||
"type": "Creatures",
|
||||
"subtype": "portal",
|
||||
"url": "1eGQsy2kYk7HfnQetsjobMqank4bg6iWOOaSYykg3Yec"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Mugic"},
|
||||
"gsx$subtype": {"$t": "cards"},
|
||||
"gsx$url": {"$t": "1rOMFKnWaz6XmhD43YFpcemWGzEok9IgtKCoiPMwA35s"}
|
||||
"type": "Mugic",
|
||||
"subtype": "cards",
|
||||
"url": "1rOMFKnWaz6XmhD43YFpcemWGzEok9IgtKCoiPMwA35s"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Mugic"},
|
||||
"gsx$subtype": {"$t": "portal"},
|
||||
"gsx$url": {"$t": "1tEuwPGixJH2A03YtYL6Ar-MSFvtfrlaveT98GwJhw1g"}
|
||||
"type": "Mugic",
|
||||
"subtype": "portal",
|
||||
"url": "1tEuwPGixJH2A03YtYL6Ar-MSFvtfrlaveT98GwJhw1g"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Attacks"},
|
||||
"gsx$subtype": {"$t": "cards"},
|
||||
"gsx$url": {"$t": "1yXFijC2hN1vybU3ejdINYoTOTG62qCkpPLPsiYUEEyo"}
|
||||
"type": "Attacks",
|
||||
"subtype": "cards",
|
||||
"url": "1yXFijC2hN1vybU3ejdINYoTOTG62qCkpPLPsiYUEEyo"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Attacks"},
|
||||
"gsx$subtype": {"$t": "portal"},
|
||||
"gsx$url": {"$t": "1KUk5J-3ZeMlEBXOfDb2h4GUUJK_0_yOq0EUDitQgNa8"}
|
||||
"type": "Attacks",
|
||||
"subtype": "portal",
|
||||
"url": "1KUk5J-3ZeMlEBXOfDb2h4GUUJK_0_yOq0EUDitQgNa8"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Battlegear"},
|
||||
"gsx$subtype": {"$t": "cards"},
|
||||
"gsx$url": {"$t": "1UUEPAEHZwmH52AJj2Jtskf6d4z5XIFEBb3HT-FTAcgs"}
|
||||
"type": "Battlegear",
|
||||
"subtype": "cards",
|
||||
"url": "1UUEPAEHZwmH52AJj2Jtskf6d4z5XIFEBb3HT-FTAcgs"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Battlegear"},
|
||||
"gsx$subtype": {"$t": "portal"},
|
||||
"gsx$url": {"$t": "1S5AVw-E_sFO257uzajauP31bOI0LPmrbTcUzSpa2i60"}
|
||||
"type": "Battlegear",
|
||||
"subtype": "portal",
|
||||
"url": "1S5AVw-E_sFO257uzajauP31bOI0LPmrbTcUzSpa2i60"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Locations"},
|
||||
"gsx$subtype": {"$t": "cards"},
|
||||
"gsx$url": {"$t": "15QPS08iq6pkyMFsYuDsKIXX8LQmQ8MUoJeeNtjU54Xo"}
|
||||
"type": "Locations",
|
||||
"subtype": "cards",
|
||||
"url": "15QPS08iq6pkyMFsYuDsKIXX8LQmQ8MUoJeeNtjU54Xo"
|
||||
},
|
||||
{
|
||||
"gsx$type": {"$t": "Locations"},
|
||||
"gsx$subtype": {"$t": "portal"},
|
||||
"gsx$url": {"$t": "1U07n2keHNxL-6y5zUcHlb220zT9A_MrVEansOAMQFCA"}
|
||||
"type": "Locations",
|
||||
"subtype": "portal",
|
||||
"url": "1U07n2keHNxL-6y5zUcHlb220zT9A_MrVEansOAMQFCA"
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -7,9 +7,7 @@ function cleanInputRegex(input, check=true) {
|
|||
const testRegex = /[\^$+*\[\]|]/g;
|
||||
if (testRegex.test(input)) {
|
||||
try {
|
||||
const returnRegex = new RegExp(input, 'i');
|
||||
console.log(returnRegex);
|
||||
return returnRegex;
|
||||
return new RegExp(input, 'i');
|
||||
} catch (e) {/* */}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,9 +20,7 @@ function cleanInputRegex(input, check=true) {
|
|||
});
|
||||
// .replace(/~(\w+)/, (match) => (`\(?!${match}\)`));
|
||||
|
||||
const returnRegex = new RegExp(input, 'i');
|
||||
console.log(returnRegex);
|
||||
return returnRegex;
|
||||
return new RegExp(input, 'i');
|
||||
}
|
||||
|
||||
export default function search_api(input) {
|
||||
|
|
|
|||
|
|
@ -41,9 +41,11 @@ const EnterTheCode = () => {
|
|||
});
|
||||
|
||||
useEffect(() => {
|
||||
API.getSpreadsheet(API.path("1hzSojB76Me-P1qppxYR0oiHSU56jyK59x3DKm660ntc"), false, (data: any) => {
|
||||
setFanData(data);
|
||||
});
|
||||
API.parseSpreadsheetData("1hzSojB76Me-P1qppxYR0oiHSU56jyK59x3DKm660ntc", "fan")
|
||||
.then(cards => {
|
||||
setFanData(cards);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
if (fanData === null) {
|
||||
|
|
@ -69,11 +71,11 @@ const EnterTheCode = () => {
|
|||
else {
|
||||
const card = fanData[getRandomInt(0, fanData.length)];
|
||||
const rgx = /.*.png|.*.jpg/i;
|
||||
const img = (rgx.test(card.gsx$image.$t) ? card.gsx$image.$t : API.base_image + card.gsx$image.$t);
|
||||
const img = (rgx.test(card.gsx$image) ? card.gsx$image : API.base_image + card.gsx$image);
|
||||
setMessage(
|
||||
<>
|
||||
<p> Congrats on your scan! </p><br />
|
||||
<p className="bigger"> {card.gsx$name.$t} </p><br />
|
||||
<p className="bigger"> {card.gsx$name} </p><br />
|
||||
<img className="card" src={img} />
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ export default function PackSimulator () {
|
|||
|
||||
useEffect(() => {
|
||||
API.LoadDB([{ 'cards': 'attacks' }, { 'cards': 'battlegear' }, { 'cards': 'creatures' }, { 'cards': 'locations' }, { 'cards': 'mugic' }])
|
||||
.then(() => {
|
||||
setupDB();
|
||||
setLoaded(true);
|
||||
})
|
||||
.catch(() => {});
|
||||
.then(() => {
|
||||
setupDB();
|
||||
setLoaded(true);
|
||||
})
|
||||
.catch(() => {});
|
||||
|
||||
const cards = [];
|
||||
for (let i = 0; i < 9; i++) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user