From cf3873d62ff30da691dae7f7424c6365b5a72edc Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Sun, 17 Jul 2022 18:52:41 +0200 Subject: Add local disk caching for fetched assets --- api/assets/inline-plugins/autoRegister.js | 62 ++++++++++++++++++++++++++++ api/assets/inline-plugins/fosscord-login.js | 12 ++++++ api/assets/preload-plugins/autoRegister.js | 62 ---------------------------- api/assets/preload-plugins/fosscord-login.js | 12 ------ 4 files changed, 74 insertions(+), 74 deletions(-) create mode 100644 api/assets/inline-plugins/autoRegister.js create mode 100644 api/assets/inline-plugins/fosscord-login.js delete mode 100644 api/assets/preload-plugins/autoRegister.js delete mode 100644 api/assets/preload-plugins/fosscord-login.js (limited to 'api/assets') diff --git a/api/assets/inline-plugins/autoRegister.js b/api/assets/inline-plugins/autoRegister.js new file mode 100644 index 00000000..bb0b903d --- /dev/null +++ b/api/assets/inline-plugins/autoRegister.js @@ -0,0 +1,62 @@ +// Auto register guest account: +const prefix = [ + "mysterious", + "adventurous", + "courageous", + "precious", + "cynical", + "flamer ", + "despicable", + "suspicious", + "gorgeous", + "impeccable", + "lovely", + "stunning", + "keyed", + "phoned", + "glorious", + "amazing", + "strange", + "arcane" +]; +const suffix = [ + "Anonymous", + "Boy", + "Lurker", + "Keyhitter", + "User", + "Enjoyer", + "Hunk", + "Coolstar", + "Wrestling", + "TylerTheCreator", + "Ad", + "Gamer", + "Games", + "Programmer" +]; + +Array.prototype.random = function () { + return this[Math.floor(Math.random() * this.length)]; +}; + +function _generateName() { + return `${prefix.random()}${suffix.random()}`; +} + +var token = JSON.parse(localStorage.getItem("token")); +if (!token && location.pathname !== "/login" && location.pathname !== "/register") { + fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)} + }) + .then((x) => x.json()) + .then((x) => { + localStorage.setItem("token", `"${x.token}"`); + if (!window.localStorage) { + // client already loaded -> need to reload to apply the newly registered user token + location.reload(); + } + }); +} diff --git a/api/assets/inline-plugins/fosscord-login.js b/api/assets/inline-plugins/fosscord-login.js new file mode 100644 index 00000000..38f82200 --- /dev/null +++ b/api/assets/inline-plugins/fosscord-login.js @@ -0,0 +1,12 @@ +// Remove `` from header when we're not accessing `/login` or `/register` +// fosscord-login.css replaces discord's TOS tooltip with something more fitting for fosscord, which when included in the main app, causes other tooltips +// to be affected, which is potentially unwanted. +// +// This script removes fosscord-login.css when a user reloads the page. From testing, it appears fosscord already properly removes +// fosscord-login.css after login is successful, but not if you reload the page after logging in. This script is to remove fosscord-login.css in +// that specific case. + +var token = JSON.parse(localStorage.getItem("token")); +if (!token && location.pathname !== "/login" && location.pathname !== "/register") { + document.getElementById("logincss").remove(); +} diff --git a/api/assets/preload-plugins/autoRegister.js b/api/assets/preload-plugins/autoRegister.js deleted file mode 100644 index bb0b903d..00000000 --- a/api/assets/preload-plugins/autoRegister.js +++ /dev/null @@ -1,62 +0,0 @@ -// Auto register guest account: -const prefix = [ - "mysterious", - "adventurous", - "courageous", - "precious", - "cynical", - "flamer ", - "despicable", - "suspicious", - "gorgeous", - "impeccable", - "lovely", - "stunning", - "keyed", - "phoned", - "glorious", - "amazing", - "strange", - "arcane" -]; -const suffix = [ - "Anonymous", - "Boy", - "Lurker", - "Keyhitter", - "User", - "Enjoyer", - "Hunk", - "Coolstar", - "Wrestling", - "TylerTheCreator", - "Ad", - "Gamer", - "Games", - "Programmer" -]; - -Array.prototype.random = function () { - return this[Math.floor(Math.random() * this.length)]; -}; - -function _generateName() { - return `${prefix.random()}${suffix.random()}`; -} - -var token = JSON.parse(localStorage.getItem("token")); -if (!token && location.pathname !== "/login" && location.pathname !== "/register") { - fetch(`${window.GLOBAL_ENV.API_ENDPOINT}/auth/register`, { - method: "POST", - headers: { "content-type": "application/json" }, - body: JSON.stringify({ username: `${_generateName()}`, consent: true }) //${Date.now().toString().slice(-4)} - }) - .then((x) => x.json()) - .then((x) => { - localStorage.setItem("token", `"${x.token}"`); - if (!window.localStorage) { - // client already loaded -> need to reload to apply the newly registered user token - location.reload(); - } - }); -} diff --git a/api/assets/preload-plugins/fosscord-login.js b/api/assets/preload-plugins/fosscord-login.js deleted file mode 100644 index 38f82200..00000000 --- a/api/assets/preload-plugins/fosscord-login.js +++ /dev/null @@ -1,12 +0,0 @@ -// Remove `` from header when we're not accessing `/login` or `/register` -// fosscord-login.css replaces discord's TOS tooltip with something more fitting for fosscord, which when included in the main app, causes other tooltips -// to be affected, which is potentially unwanted. -// -// This script removes fosscord-login.css when a user reloads the page. From testing, it appears fosscord already properly removes -// fosscord-login.css after login is successful, but not if you reload the page after logging in. This script is to remove fosscord-login.css in -// that specific case. - -var token = JSON.parse(localStorage.getItem("token")); -if (!token && location.pathname !== "/login" && location.pathname !== "/register") { - document.getElementById("logincss").remove(); -} -- cgit 1.4.1 From f3b1e9b02641376177c4c358074e01f201ba0ff8 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sat, 30 Jul 2022 14:33:01 -0400 Subject: add discriminator to user modify schema --- api/assets/schemas.json | 5 +++++ api/src/routes/users/@me/index.ts | 1 + 2 files changed, 6 insertions(+) (limited to 'api/assets') diff --git a/api/assets/schemas.json b/api/assets/schemas.json index ca42e676..f7efb888 100644 --- a/api/assets/schemas.json +++ b/api/assets/schemas.json @@ -12499,6 +12499,11 @@ "maxLength": 100, "type": "string" }, + "discriminator": { + "minLength": 4, + "maxLength": 4, + "type": "string" + }, "avatar": { "type": [ "null", diff --git a/api/src/routes/users/@me/index.ts b/api/src/routes/users/@me/index.ts index 1af413c4..7fc20457 100644 --- a/api/src/routes/users/@me/index.ts +++ b/api/src/routes/users/@me/index.ts @@ -11,6 +11,7 @@ export interface UserModifySchema { * @maxLength 100 */ username?: string; + discriminator?: string; avatar?: string | null; /** * @maxLength 1024 -- cgit 1.4.1 From 243417a66728c6494c5718b550ce2f677bba77a7 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sat, 30 Jul 2022 17:34:14 -0400 Subject: Update schemas.json --- api/assets/schemas.json | 2 -- 1 file changed, 2 deletions(-) (limited to 'api/assets') diff --git a/api/assets/schemas.json b/api/assets/schemas.json index f7efb888..9c312123 100644 --- a/api/assets/schemas.json +++ b/api/assets/schemas.json @@ -12500,8 +12500,6 @@ "type": "string" }, "discriminator": { - "minLength": 4, - "maxLength": 4, "type": "string" }, "avatar": { -- cgit 1.4.1