This commit is contained in:
2021-03-09 01:13:42 +01:00
commit 7fc8feb0cc
32 changed files with 3700 additions and 0 deletions

View File

@ -0,0 +1,7 @@
import { writable } from "svelte/store";
const r = "route" in localStorage ? localStorage.getItem("route"):"main";
const store = writable<string>(r);
export default store;

63
view/src/stores/images.ts Normal file
View File

@ -0,0 +1,63 @@
import { writable } from "svelte/store";
import { openDB, DBSchema } from 'idb';
interface Image {
name: string,
filename: string
lastModified: number
type: string
data: ArrayBuffer
}
interface ImageDB extends DBSchema {
images: {
value: Image;
key: string;
indexes: { 'filename': string };
};
}
const db = openDB<ImageDB>('Images', 1, {
upgrade(db) {
// Create a store of objects
const store = db.createObjectStore('images', {
// The 'id' property of the object will be the key.
keyPath: 'id',
// If it isn't explicitly set, create a value by auto incrementing.
autoIncrement: true,
});
// Create an index on the 'date' property of the objects.
store.createIndex('filename', 'filename');
},
});
const store = writable<Image[]>([]);
async function add(img: Image | Image[]) {
const images = Array.isArray(img) ? [...img] : [img];
const tx = (await db).transaction('images', 'readwrite');
await Promise.all(images.map(img => tx.store.add(img)));
await tx.done;
}
async function get(name: string): Promise<Image> {
return new Promise((res, rej) => {
res({} as Image);
})
}
async function getAll(): Promise<Image[]> {
return (await db).getAll("images");
}
(async () => store.set(await getAll()))()
export { store, add, get, getAll };

3
view/src/stores/index.ts Normal file
View File

@ -0,0 +1,3 @@
import * as images from "./images";
export { images }
export { default as route } from "./route";

18
view/src/stores/route.ts Normal file
View File

@ -0,0 +1,18 @@
import { writable } from "svelte/store";
let r = "main";
if (window.location.hash.length) {
r = window.location.hash.replace("#", "");
} else {
r = "main";
}
const store = writable<string>(r);
store.subscribe(s => {
if (s === "main") s = ""
window.location.hash = s;
})
export default store;