1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2025-02-21 06:29:02 +00:00

github: each repo in a separate localstorage key

This commit is contained in:
Steven Hugg 2019-05-26 10:54:36 -04:00
parent 89c608dc2c
commit bafee9d55d
3 changed files with 24 additions and 9 deletions

View File

@ -71,7 +71,6 @@ TODO:
- what if error in include file you can't edit b/c it never appears? - what if error in include file you can't edit b/c it never appears?
- markdown, verilog: can't share - markdown, verilog: can't share
- https://www.crowdsupply.com/tinyfpga/tinyfpga-bx - https://www.crowdsupply.com/tinyfpga/tinyfpga-bx
- HTTPS warning
- stego shareable images (http://pico-8.wikia.com/wiki/P8PNGFileFormat) - stego shareable images (http://pico-8.wikia.com/wiki/P8PNGFileFormat)
- https://makecode.com/language? - https://makecode.com/language?
- open ROM from URL? - open ROM from URL?

View File

@ -10,6 +10,7 @@ declare var firebase;
export interface GHRepoMetadata { export interface GHRepoMetadata {
url : string; // github url url : string; // github url
platform_id : string; // e.g. "vcs" platform_id : string; // e.g. "vcs"
sha? : string; // head commit sha
mainPath?: string; // main file path mainPath?: string; // main file path
} }
@ -31,7 +32,16 @@ export interface GHSession extends GHRepoMetadata {
const README_md_template = "$NAME\n=====\n\n[Open this project in 8bitworkshop](http://8bitworkshop.com/redir.html?platform=$PLATFORM&importURL=$GITHUBURL&file=$MAINFILE).\n"; const README_md_template = "$NAME\n=====\n\n[Open this project in 8bitworkshop](http://8bitworkshop.com/redir.html?platform=$PLATFORM&importURL=$GITHUBURL&file=$MAINFILE).\n";
export function getRepos() : {[key:string]:GHRepoMetadata} { export function getRepos() : {[key:string]:GHRepoMetadata} {
return JSON.parse(localStorage.getItem('__repos') || '{}'); var repos = {};
for (var i=0; i<localStorage.length; i++) {
var key = localStorage.key(i);
if (key.startsWith('__repo__')) {
var repodata : GHRepoMetadata = JSON.parse(localStorage.getItem(key));
var path = key.substring('__repo__'.length);
repos[path] = repodata;
}
}
return repos;
} }
export function parseGithubURL(ghurl:string) { export function parseGithubURL(ghurl:string) {
@ -134,7 +144,8 @@ export class GithubService {
}) })
.then( (head) => { .then( (head) => {
sess.head = head; sess.head = head;
return sess.repo.git.trees(head.object.sha).fetch(); sess.sha = head.object.sha;
return sess.repo.git.trees(sess.sha).fetch();
}) })
.then( (tree) => { .then( (tree) => {
if (sess.subtreepath) { if (sess.subtreepath) {
@ -154,13 +165,13 @@ export class GithubService {
} }
bind(sess:GHSession, dobind:boolean) { bind(sess:GHSession, dobind:boolean) {
var repos = getRepos(); var key = '__repo__' + sess.repopath;
if (dobind) { if (dobind) {
repos[sess.repopath] = {url:sess.url, platform_id:sess.platform_id, mainPath:sess.mainPath}; var repodata : GHRepoMetadata = {url:sess.url, platform_id:sess.platform_id, mainPath:sess.mainPath, sha:sess.sha};
localStorage.setItem(key, JSON.stringify(repodata));
} else { } else {
delete repos[sess.repopath]; localStorage.removeItem(key);
} }
localStorage.setItem('__repos', JSON.stringify(repos));
} }
import(ghurl:string) : Promise<GHSession> { import(ghurl:string) : Promise<GHSession> {

View File

@ -15,7 +15,7 @@ var Octokat = require('octokat');
var test_platform_id = "_TEST"; var test_platform_id = "_TEST";
function newGH(store, platform_id) { function newGH(store, platform_id) {
localStorage.removeItem('__repos'); localStorage.clear();
// pzpinfo user // pzpinfo user
var project = new prj.CodeProject({}, platform_id||test_platform_id, null, store); var project = new prj.CodeProject({}, platform_id||test_platform_id, null, store);
project.mainPath = 'local/main.asm'; project.mainPath = 'local/main.asm';
@ -33,7 +33,12 @@ describe('Store', function() {
gh.importAndPull('https://github.com/pzpinfo/test123123/').then( (sess) => { gh.importAndPull('https://github.com/pzpinfo/test123123/').then( (sess) => {
console.log(sess.paths); console.log(sess.paths);
assert.equal(2, sess.paths.length); assert.equal(2, sess.paths.length);
assert.deepEqual(serv.getRepos(), {"pzpinfo/test123123":{url: 'https://github.com/pzpinfo/test123123/', platform_id: 'vcs', mainPath:'helloworld.bas'}}); assert.deepEqual(serv.getRepos(), {"pzpinfo/test123123":{
url: 'https://github.com/pzpinfo/test123123/',
platform_id: 'vcs',
mainPath:'helloworld.bas',
//sha:'e466d777810838065b7682587ca592c3eefc0b1c'
}});
done(); done();
}); });
}); });