mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2024-05-31 13:41:32 +00:00
updated firebase, refactored ProjectFilesystem
This commit is contained in:
parent
a63b1230a7
commit
4ccf588c80
|
@ -34,8 +34,9 @@ if (window.location.host.endsWith('8bitworkshop.com')) {
|
||||||
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
||||||
|
|
||||||
<!-- firebase libs -->
|
<!-- firebase libs -->
|
||||||
<script defer src="https://www.gstatic.com/firebasejs/5.11.1/firebase-app.js"></script>
|
<script defer src="https://www.gstatic.com/firebasejs/8.3.2/firebase-app.js"></script>
|
||||||
<script defer src="https://www.gstatic.com/firebasejs/5.11.1/firebase-auth.js"></script>
|
<script defer src="https://www.gstatic.com/firebasejs/8.3.2/firebase-auth.js"></script>
|
||||||
|
<script defer src="https://www.gstatic.com/firebasejs/8.3.2/firebase-database.js"></script>
|
||||||
<script defer src="config.js"></script>
|
<script defer src="config.js"></script>
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -11,7 +11,6 @@ export interface ProjectFilesystem {
|
||||||
export class WebPresetsFileSystem implements ProjectFilesystem {
|
export class WebPresetsFileSystem implements ProjectFilesystem {
|
||||||
preset_id : string;
|
preset_id : string;
|
||||||
constructor(platform_id: string) {
|
constructor(platform_id: string) {
|
||||||
// found on remote fetch?
|
|
||||||
this.preset_id = getBasePlatform(platform_id); // remove .suffix from preset name
|
this.preset_id = getBasePlatform(platform_id); // remove .suffix from preset name
|
||||||
}
|
}
|
||||||
async getRemoteFile(path: string): Promise<FileData> {
|
async getRemoteFile(path: string): Promise<FileData> {
|
||||||
|
@ -20,6 +19,7 @@ export class WebPresetsFileSystem implements ProjectFilesystem {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async getFileData(path: string) : Promise<FileData> {
|
async getFileData(path: string) : Promise<FileData> {
|
||||||
|
// found on remote fetch?
|
||||||
var webpath = "presets/" + this.preset_id + "/" + path;
|
var webpath = "presets/" + this.preset_id + "/" + path;
|
||||||
var data = await this.getRemoteFile(webpath);
|
var data = await this.getRemoteFile(webpath);
|
||||||
if (data) console.log("read",webpath,data.length,'bytes');
|
if (data) console.log("read",webpath,data.length,'bytes');
|
||||||
|
@ -44,23 +44,37 @@ export class NullFilesystem implements ProjectFilesystem {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LocalForageFilesystem implements ProjectFilesystem {
|
export class OverlayFilesystem implements ProjectFilesystem {
|
||||||
basefs: ProjectFilesystem;
|
basefs: ProjectFilesystem;
|
||||||
store: any;
|
overlayfs: ProjectFilesystem;
|
||||||
constructor(store: any, basefs: ProjectFilesystem) {
|
constructor(basefs: ProjectFilesystem, overlayfs: ProjectFilesystem) {
|
||||||
this.store = store;
|
|
||||||
this.basefs = basefs;
|
this.basefs = basefs;
|
||||||
|
this.overlayfs = overlayfs;
|
||||||
}
|
}
|
||||||
async getFileData(path: string): Promise<FileData> {
|
async getFileData(path: string): Promise<FileData> {
|
||||||
var data = await this.store.getItem(path);
|
var data = await this.overlayfs.getFileData(path);
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
data = await this.basefs.getFileData(path);
|
return this.basefs.getFileData(path);
|
||||||
|
} else {
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
}
|
}
|
||||||
async setFileData(path: string, data: FileData): Promise<void> {
|
async setFileData(path: string, data: FileData): Promise<void> {
|
||||||
await this.store.setItem(path, data);
|
await this.overlayfs.setFileData(path, data);
|
||||||
await this.basefs.setFileData(path, data);
|
return this.basefs.setFileData(path, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LocalForageFilesystem {
|
||||||
|
store: any;
|
||||||
|
constructor(store: any) {
|
||||||
|
this.store = store;
|
||||||
|
}
|
||||||
|
async getFileData(path: string): Promise<FileData> {
|
||||||
|
return this.store.getItem(path);
|
||||||
|
}
|
||||||
|
async setFileData(path: string, data: FileData): Promise<void> {
|
||||||
|
return this.store.setItem(path, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
import { getFolderForPath, isProbablyBinary, stringToByteArray, byteArrayToString, byteArrayToUTF8 } from "../common/util";
|
import { getFolderForPath, isProbablyBinary, stringToByteArray, byteArrayToString, byteArrayToUTF8 } from "../common/util";
|
||||||
import { FileData } from "../common/workertypes";
|
import { FileData } from "../common/workertypes";
|
||||||
import { CodeProject } from "./project";
|
import { CodeProject, ProjectFilesystem } from "./project";
|
||||||
|
|
||||||
// in index.html
|
// in index.html
|
||||||
declare var exports;
|
declare var exports;
|
||||||
|
@ -370,3 +370,27 @@ export class GithubService {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
export class FirebaseProjectFilesystem implements ProjectFilesystem {
|
||||||
|
ref;
|
||||||
|
constructor(user_id: string, store_id: string) {
|
||||||
|
var database = firebase.database();
|
||||||
|
this.ref = database.ref('users/' + user_id + "/" + store_id);
|
||||||
|
}
|
||||||
|
getChildForPath(path:string) {
|
||||||
|
var encodedPath = encodeURIComponent(path).replace('-','%2D').replace('.','%2E');
|
||||||
|
return this.ref.child(encodedPath);
|
||||||
|
}
|
||||||
|
async getFileData(path: string): Promise<FileData> {
|
||||||
|
console.log(this.getChildForPath("test"));
|
||||||
|
var snapshot = await this.getChildForPath(path).get();
|
||||||
|
return snapshot.exists() ? snapshot.val().filedata : null;
|
||||||
|
}
|
||||||
|
async setFileData(path: string, data: FileData): Promise<void> {
|
||||||
|
return this.getChildForPath(path).set({
|
||||||
|
filedata: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
import $ = require("jquery");
|
import $ = require("jquery");
|
||||||
import * as bootstrap from "bootstrap";
|
import * as bootstrap from "bootstrap";
|
||||||
import { CodeProject, LocalForageFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
|
import { CodeProject, LocalForageFilesystem, OverlayFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
|
||||||
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "../common/workertypes";
|
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "../common/workertypes";
|
||||||
import { ProjectWindows } from "./windows";
|
import { ProjectWindows } from "./windows";
|
||||||
import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuState } from "../common/baseplatform";
|
import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuState } from "../common/baseplatform";
|
||||||
|
@ -13,7 +13,7 @@ import { createNewPersistentStore } from "./store";
|
||||||
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
|
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
|
||||||
byteArrayToUTF8, isProbablyBinary, getWithBinary, getBasePlatform, getRootBasePlatform, hex } from "../common/util";
|
byteArrayToUTF8, isProbablyBinary, getWithBinary, getBasePlatform, getRootBasePlatform, hex } from "../common/util";
|
||||||
import { StateRecorderImpl } from "../common/recorder";
|
import { StateRecorderImpl } from "../common/recorder";
|
||||||
import { GHSession, GithubService, getRepos, parseGithubURL } from "./services";
|
import { GHSession, GithubService, getRepos, parseGithubURL, FirebaseProjectFilesystem } from "./services";
|
||||||
|
|
||||||
// external libs (TODO)
|
// external libs (TODO)
|
||||||
declare var Tour, GIF, saveAs, JSZip, Mousetrap, Split, firebase;
|
declare var Tour, GIF, saveAs, JSZip, Mousetrap, Split, firebase;
|
||||||
|
@ -170,7 +170,11 @@ function unsetLastPreset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initProject() {
|
function initProject() {
|
||||||
var filesystem = new LocalForageFilesystem(store, new WebPresetsFileSystem(platform_id));
|
var basefs : ProjectFilesystem = new WebPresetsFileSystem(platform_id);
|
||||||
|
//basefs = new FirebaseProjectFilesystem("TEST", "TEST");
|
||||||
|
var filesystem = new OverlayFilesystem(
|
||||||
|
basefs,
|
||||||
|
new LocalForageFilesystem(store));
|
||||||
current_project = new CodeProject(newWorker(), platform_id, platform, filesystem);
|
current_project = new CodeProject(newWorker(), platform_id, platform, filesystem);
|
||||||
projectWindows = new ProjectWindows($("#workspace")[0] as HTMLElement, current_project);
|
projectWindows = new ProjectWindows($("#workspace")[0] as HTMLElement, current_project);
|
||||||
if (isElectronWorkspace) {
|
if (isElectronWorkspace) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ function newGH(store, platform_id) {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
// pzpinfo user
|
// pzpinfo user
|
||||||
var pid = platform_id||test_platform_id;
|
var pid = platform_id||test_platform_id;
|
||||||
var fs = new prj.LocalForageFilesystem(store, new prj.NullFilesystem());
|
var fs = new prj.LocalForageFilesystem(store);
|
||||||
var project = new prj.CodeProject({}, pid, null, fs);
|
var project = new prj.CodeProject({}, pid, null, fs);
|
||||||
project.mainPath = 'local/main.asm';
|
project.mainPath = 'local/main.asm';
|
||||||
project.updateFileInStore(project.mainPath, '\torg $0 ; test\n');
|
project.updateFileInStore(project.mainPath, '\torg $0 ; test\n');
|
||||||
|
|
|
@ -13,7 +13,9 @@ var prj = require("gen/ide/project.js");
|
||||||
var test_platform_id = "_TEST";
|
var test_platform_id = "_TEST";
|
||||||
|
|
||||||
function newFilesystem(store, platform_id) {
|
function newFilesystem(store, platform_id) {
|
||||||
return new prj.LocalForageFilesystem(store, new prj.NullFilesystem());
|
return new prj.OverlayFilesystem(
|
||||||
|
new prj.NullFilesystem(),
|
||||||
|
new prj.LocalForageFilesystem(store));
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Store', function () {
|
describe('Store', function () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user