From abe58f4b3b450bd404d438c3574f51d300375449 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 10 Feb 2021 16:27:12 +0100 Subject: [PATCH] add factorio.school as a source closes #227 --- README.md | 2 +- packages/editor/src/core/bpString.ts | 16 +++++++++++----- packages/website/src/index.html | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 91b4417..6aeb63f 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Example blueprint book: https://fbe.teoxoy.com/?source=https://pastebin.com/Xp9u - rendering and editing blueprints - history (undo/redo) - copy and delete selections -- import blueprints and books from multiple sources (direct bp string, pastebin, hastebin, gist, gitlab, factorioprints, google docs) +- import blueprints and books from multiple sources (direct bp string, pastebin, hastebin, gist, gitlab, factorioprints, factorio.school, google docs) - generating blueprint images - oil outpost generator - customizable keybinds diff --git a/packages/editor/src/core/bpString.ts b/packages/editor/src/core/bpString.ts index 7aca9e2..1fb9868 100644 --- a/packages/editor/src/core/bpString.ts +++ b/packages/editor/src/core/bpString.ts @@ -158,15 +158,15 @@ function getBlueprintOrBookFromSource(source: string): Promise }) // TODO: add dropbox support https://www.dropbox.com/s/ID?raw=1 - switch (url.hostname.split('.')[0]) { + switch (url.hostname.replace(/^www\./, '').split('.')[0]) { case 'pastebin': return fetchData(`https://pastebin.com/raw/${pathParts[0]}`).then(r => r.text()) case 'hastebin': return fetchData(`https://hastebin.com/raw/${pathParts[0]}`).then(r => r.text()) case 'gist': - return fetchData(`https://api.github.com/gists/${pathParts[1]}`).then(r => - r.json().then(data => data.files[Object.keys(data.files)[0]].content) - ) + return fetchData(`https://api.github.com/gists/${pathParts[1]}`) + .then(r => r.json()) + .then(data => data.files[Object.keys(data.files)[0]].content) case 'gitlab': return fetchData(`https://gitlab.com/${pathParts.join('/')}/raw`).then(r => r.text() @@ -174,7 +174,13 @@ function getBlueprintOrBookFromSource(source: string): Promise case 'factorioprints': return fetchData( `https://facorio-blueprints.firebaseio.com/blueprints/${pathParts[1]}.json` - ).then(r => r.json().then(data => data.blueprintString)) + ) + .then(r => r.json()) + .then(data => data.blueprintString) + case 'factorio': // factorio.school + return fetchData(`https://www.factorio.school/api/blueprint/${pathParts[1]}`) + .then(r => r.json()) + .then(data => data.blueprintString.blueprintString) case 'docs': return fetchData( `https://docs.google.com/document/d/${pathParts[2]}/export?format=txt` diff --git a/packages/website/src/index.html b/packages/website/src/index.html index 867e365..74ef8aa 100644 --- a/packages/website/src/index.html +++ b/packages/website/src/index.html @@ -67,7 +67,7 @@
  • copy and delete selections
  • import blueprints and books from multiple sources (direct bp string, pastebin, - hastebin, gist, gitlab, factorioprints, google docs) + hastebin, gist, gitlab, factorioprints, factorio.school, google docs)
  • generating blueprint images
  • oil outpost generator