Skip to content

Commit

Permalink
remove external gists library, setup the stage for github
Browse files Browse the repository at this point in the history
  • Loading branch information
blurymind committed Apr 8, 2024
1 parent 7b9f768 commit 428fa6d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 66 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"bbcode": "^0.1.5",
"bondage": "^2.0.1",
"file-saver": "^2.0.2",
"gists": "^2.0.0",
"inkjs": "^2.2.0",
"jquery": "^3.4.1",
"jquery-contextmenu": "^2.8.0",
Expand Down
6 changes: 3 additions & 3 deletions src/js/classes/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export var App = function(name, version) {
};

this.setGistCredentials = function(gist, e) {
console.log("SET CREDENTIALS")
const { token, file } = gist;
const Gists = require('gists');
const gists = new Gists({ token });
self.gists = gists;
self.gists = self.settings.cloudStorage("gist", {token, file});
self.gists.file = file;
self.gists.token = token;
};

// Ideally this dependencies should be injected by index.js
Expand Down
12 changes: 6 additions & 6 deletions src/js/classes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,7 @@ export const data = {
console.log(gistFiles);
data.promptFileNameAndFormat(({ editingName, yarnData }) => {
data.editingName(editingName);
gists.edit(gists.file, {
files: { [editingName]: { content: yarnData } },
});
gists.edit(gists.file, editingName, yarnData);
Swal.fire(
'Saved!',
`The Yarn has been saved to gist ${gists.file}`,
Expand Down Expand Up @@ -1209,7 +1207,9 @@ export const data = {
const previouslyOpenedGist =
data.lastStorageHost() === 'GIST' ? data.editingName() : '';
gists.get(gists.file).then(gist => {
console.log("GOT", gist)
const gistFiles = gist.body.files;
console.log({gistFiles})
const inputOptions = {};
Object.keys(gistFiles).forEach(key => {
inputOptions[key] = key;
Expand All @@ -1225,8 +1225,10 @@ export const data = {
inputPlaceholder: 'Select a file from the gist',
showCancelButton: true,
}).then(({ value }) => {
console.log("GOT data from gist", {value, gistFiles})
if (value) {
const content = gistFiles[value].content;
console.log({content})
data.openGist(content, value);
}
});
Expand Down Expand Up @@ -1274,9 +1276,7 @@ export const data = {
gists.get(gists.file).then(gist => {
data.getSaveData(data.editingType()).then(yarnData => {
data.getSaveData(data.editingType());
gists.edit(gists.file, {
files: { [data.editingName()]: { content: yarnData } },
});
gists.edit(gists.file, data.editingName(), yarnData);
data.lastStorageHost('GIST');
data.isDocumentDirty(false);
app.refreshWindowTitle();
Expand Down
77 changes: 77 additions & 0 deletions src/js/classes/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,87 @@ const getStorage = function() {
}
};

const getCloudStorage = function(type = 'gist', credentials) {
if (type === 'gist') {
return {
get: gistId => {
return fetch('https://api.github.com/gists/' + gistId, {
method: 'GET',
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${credentials.token}`,
'X-GitHub-Api-Version': '2022-11-28'
},
})
.then(data => data.json())
.then(content => {
console.log('NEW from get::', { content });
return { body: content };
});
},
edit: (gistId, fileName, content) => {
console.log({gistId, fileName, content, credentials})
return fetch(
'https://api.github.com/gists/' + gistId,
{
method: 'POST',
headers: {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${credentials.token}`,
'X-GitHub-Api-Version': '2022-11-28'
},
body: JSON.stringify({
description: 'upload data from api',
public: false,
files: { [fileName]: { content } }
}),
}
).then(res => res.json());
}
};
} else if (type === 'github') {
// todo implement
// const getFile = function(data) {
// return fetch(
// `https://api.github.com/repos/${data.owner}/${data.repo}/contents/${data.name}`,
// {
// method: 'GET',
// headers: {
// Accept: 'application/vnd.github+json',
// Authorization: `Bearer ${data.token}`,
// },
// }
// ).then(res => res.json());
// };
// const setFile = function(data) {
// //todo this wont work unless adding sha or deleting the file first
// console.log({ setToFile: data.content, data });
// return fetch(
// `https://api.github.com/repos/${data.owner}/${data.repo}/contents/${data.name}`,
// {
// method: 'PUT',
// headers: {
// Accept: 'application/vnd.github+json',
// Authorization: `Bearer ${data.token}`,
// },
// body: JSON.stringify({
// message: 'upload data from api',
// content: data.content,
// sha: data.sha,
// }),
// }
// ).then(res => res.json());
// };
// return { getFile, setFile, credentials, setCredentials };
}
return { getFile: () => {}, setFile: () => {}, credentials, setCredentials };
};

export const Settings = function(app) {
const self = this;
const storage = getStorage();
this.storage = storage;
this.cloudStorage = getCloudStorage;

ko.extenders.persist = function(target, option) {
target.subscribe(function(newValue) {
Expand Down
58 changes: 2 additions & 56 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3212,7 +3212,7 @@ [email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
dependencies:
ms "2.0.0"

debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5, debug@^3.2.6:
debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5:
version "3.2.6"
resolved "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz"
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
Expand Down Expand Up @@ -4767,13 +4767,6 @@ get-value@^2.0.3, get-value@^2.0.6:
resolved "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz"
integrity sha1-3BXKHGcjh8p2vTesCjlbogQqLCg=

get-value@^3.0.1:
version "3.0.1"
resolved "https://registry.npmjs.org/get-value/-/get-value-3.0.1.tgz"
integrity sha512-mKZj9JLQrwMBtj5wxi6MH8Z5eSKaERpAwjg43dPtlGI1ZVEgH/qC7T8/6R2OBSUA+zzHBZgICsVJaEIV2tKTDA==
dependencies:
isobject "^3.0.1"

gh-pages@^2.0.1:
version "2.2.0"
resolved "https://registry.npmjs.org/gh-pages/-/gh-pages-2.2.0.tgz"
Expand Down Expand Up @@ -4804,25 +4797,6 @@ gifwrap@^0.9.2:
image-q "^4.0.0"
omggif "^1.0.10"

gists@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/gists/-/gists-2.0.0.tgz"
integrity sha512-EVSWDpq2/H9ITsXsjdPo9+i2MI9U4E6DirXwR7/t6Mqgnynlh9ta6RMyezIINVNhkXZTCttmiSISd7JNkI2rQw==
dependencies:
github-base "^1.0.0"

github-base@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/github-base/-/github-base-1.0.0.tgz"
integrity sha512-5A9OOCQWK80v+bjVRzdK0M/5UtERN9vx9TkJMlkiJA24wu/+lrQLsq5MPQIrSONrSWwt83eAPtBcuQOc2FyK8A==
dependencies:
get-value "^3.0.1"
needle "^2.2.2"
paged-request "^1.0.2"
parse-link-header "^1.0.1"
qs "^6.5.1"
use "^3.1.0"

glob-parent@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz"
Expand Down Expand Up @@ -5304,7 +5278,7 @@ husky@^2.7.0:
run-node "^1.0.0"
slash "^3.0.0"

[email protected], iconv-lite@^0.4.17, iconv-lite@^0.4.24, iconv-lite@^0.4.4:
[email protected], iconv-lite@^0.4.17, iconv-lite@^0.4.24:
version "0.4.24"
resolved "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
Expand Down Expand Up @@ -7055,15 +7029,6 @@ natural-compare@^1.4.0:
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

needle@^2.1.1, needle@^2.2.2:
version "2.5.0"
resolved "https://registry.npmjs.org/needle/-/needle-2.5.0.tgz"
integrity sha512-o/qITSDR0JCyCKEQ1/1bnUXMmznxabbwi/Y4WwJElf+evwJNFNwIDMCCt5IigFVxgeGBJESLohGtIS9gEzo1fA==
dependencies:
debug "^3.2.6"
iconv-lite "^0.4.4"
sax "^1.2.4"

[email protected]:
version "0.6.2"
resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz"
Expand Down Expand Up @@ -7601,13 +7566,6 @@ package-json@^6.3.0:
registry-url "^5.0.0"
semver "^6.2.0"

paged-request@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/paged-request/-/paged-request-1.0.2.tgz"
integrity sha512-2NXKpT0pWoVo31LQhGOfsqD8wViifq6Ml28H8WrqY0GbMvltvpDPx1YZ6jMeVXNbywjECdEhmC2/uFFS1MdMFQ==
dependencies:
needle "^2.1.1"

pako@^1.0.0, pako@^1.0.5, pako@~1.0.5:
version "1.0.11"
resolved "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz"
Expand Down Expand Up @@ -7711,13 +7669,6 @@ parse-json@^5.0.0:
json-parse-better-errors "^1.0.1"
lines-and-columns "^1.1.6"

parse-link-header@^1.0.1:
version "1.0.1"
resolved "https://registry.npmjs.org/parse-link-header/-/parse-link-header-1.0.1.tgz"
integrity sha1-vt/g0hGK64S+deewJUGeyKYRQKc=
dependencies:
xtend "~4.0.1"

parse-passwd@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz"
Expand Down Expand Up @@ -8444,11 +8395,6 @@ [email protected]:
resolved "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz"
integrity sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==

qs@^6.5.1:
version "6.5.2"
resolved "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz"
integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==

query-string@^4.1.0:
version "4.3.4"
resolved "https://registry.npmjs.org/query-string/-/query-string-4.3.4.tgz"
Expand Down

0 comments on commit 428fa6d

Please sign in to comment.