Fix popout alignment, gzip local storage cache array, add file watcher

Signed-off-by: 0xf8 <0xf8.dev@proton.me>
This commit is contained in:
0xf8 2023-03-01 22:29:18 -05:00
parent 0039bacd24
commit 0e30201502
Signed by: 0xf8
GPG Key ID: 446580D758689584
6 changed files with 42 additions and 73 deletions

View File

@ -4,7 +4,6 @@
"main": "dist/server.js",
"types": "dist/types.d.ts",
"version": "0.0.0",
"license": "GLP-3.0-only",
"scripts": {
"dev": "npx parcel watch & npx nodemon dist/server.js",
"build": "npx parcel build"

View File

@ -10,7 +10,7 @@ You should have received a copy of the GNU General Public License along with Gal
import { createHash } from "crypto";
import { Request, Response } from "express";
import { readdirSync, existsSync, mkdirSync, statSync, readFileSync } from "fs";
import { readdirSync, existsSync, mkdirSync, statSync, readFileSync, watch } from "fs";
import path from "path";
class Sync {
@ -35,7 +35,7 @@ class Sync {
await this.update();
res();
}
})
});
let c = createHash("sha1");
@ -61,25 +61,36 @@ class Sync {
pastchecksum: string[];
}
const state: Sync = new Sync();
let lastUpdate = Date.now();
watch(state.root, {}, (e, f) => {
let now = Date.now();
// If lastUpdate occured within 1 second
if (now - lastUpdate < 1000) {
lastUpdate = now;
return;
}
lastUpdate = now;
state.update();
});
let sync = async (req: Request, res: Response) => {
try {
switch (req.method) {
case "GET": { // "Update me"
res.status(405);
// await state.update();
// res.write(JSON.stringify({
// checksum: state.checksum,
// files: state.files
// }));
break;
}
case "POST": {
await state.update();
let reqd;
let reqd: { action: string; checksum: string; };
try {
reqd = JSON.parse(req.body);

View File

@ -6,15 +6,21 @@
"www/settings.html"
],
"version": "0.0.0",
"license": "GLP-3.0-only",
"license": "GPL-3.0-only",
"scripts": {
"dev": "npx parcel serve",
"build": "npx parcel build"
},
"devDependencies": {
"@parcel/transformer-sass": "2.8.0",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^5.5.0",
"events": "^3.1.0",
"parcel": "latest",
"process": "^0.11.10"
"process": "^0.11.10",
"stream-browserify": "^3.0.0",
"util": "^0.12.3"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.2.0",
@ -31,6 +37,5 @@
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"license": "GPL-3.0-only",
"sourceMap": false
}

View File

@ -91,7 +91,6 @@ span#title {
width: 100vw;
justify-content: center;
align-content: center;
z-index: 999;
@ -99,59 +98,7 @@ span#title {
display: block;
object-fit: contain;
border-radius: 8px;
}
.contextmenu {
position: fixed;
display: flex;
flex-direction: column;
padding: .4em 1em;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.7);
border: 2px rgba(0, 0, 0, 0.9) solid;
border-radius: 8px;
max-width: 18vw;
height: max-content;
width: max-content;
hr {
width: 5em;
background-color: rgba(255, 255, 255, 0.5);
}
:first-child {
font-weight: 600;
margin-bottom: .5em;
}
:last-child {
margin-top: .4em;
}
.option {
font-size: .9em;
width: fit-content;
height: auto;
border: 3px transparent solid;
background: transparent;
color: white;
border-radius: 6px;
}
.option:hover {
color: black;
background: white;
}
border-radius: 12px;
align-self: center;
}
}

View File

@ -18,7 +18,9 @@ You should have received a copy of the GNU General Public License along with Gal
</head>
<body>
<root></root>
<root>
</root>
<script type="module" src="index.html.tsx"></script>
</body>

View File

@ -8,6 +8,8 @@ Galerie is distributed in the hope that it will be useful, but WITHOUT ANY WARRA
You should have received a copy of the GNU General Public License along with Galerie. If not, see <https://www.gnu.org/licenses/>.
*/
import { gzipSync, gunzipSync } from "zlib";
let apiUrl: string = `${location.protocol}//${location.hostname}:8856/`;
class Favorites {
@ -115,7 +117,10 @@ class Cache {
async load(): Promise<void> {
console.log("Loading cache");
this.cache = JSON.parse(localStorage.getItem("cache")) || [];
if (localStorage.getItem("cache"))
this.cache = JSON.parse(gunzipSync(Buffer.from(localStorage.getItem("cache"), "base64")).toString());
else
this.cache = [];
this.checksum = localStorage.getItem("cache.checksum");
if (!this.cache || !this.checksum) {
@ -152,7 +157,7 @@ class Cache {
}
private async update(): Promise<void> {
localStorage.setItem("cache", JSON.stringify(this.cache));
localStorage.setItem("cache", gzipSync(JSON.stringify(this.cache)).toString("base64"));
localStorage.setItem("cache.checksum", this.checksum);
}