feat: middle save
This commit is contained in:
parent
0caad5ea57
commit
9cdd058a49
7 changed files with 58 additions and 18 deletions
|
@ -17,7 +17,7 @@ func New(app *gin.Engine) {
|
|||
app.Use(static.Serve("/assets", static.LocalFile("./assets", false)))
|
||||
|
||||
app.NoRoute(func(ctx *gin.Context) {
|
||||
ctx.HTML(200, "index.html", nil)
|
||||
ctx.File("./public/index.html")
|
||||
})
|
||||
|
||||
app.GET("favicon.ico", func(ctx *gin.Context) {
|
||||
|
@ -52,8 +52,10 @@ func New(app *gin.Engine) {
|
|||
|
||||
entries := make([]service.DirEntry, 0)
|
||||
for _, fd := range entry {
|
||||
var info, _ = fd.Info()
|
||||
entries = append(entries, service.DirEntry{
|
||||
Name: fd.Name(),
|
||||
FileSize: uint64(info.Size()),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ type WorkerService struct{}
|
|||
|
||||
type DirEntry struct {
|
||||
Name string `json:"name"`
|
||||
FileSize uint64 `json:"file_size"`
|
||||
}
|
||||
|
||||
func NewWorkerService() *WorkerService {
|
||||
|
|
|
@ -1,7 +1,28 @@
|
|||
import { useEffect, useState } from "react";
|
||||
import Directory from "../directory";
|
||||
import { usePath } from "../../store/path";
|
||||
import { useLocation } from "react-router";
|
||||
|
||||
import "./dashboard.scss";
|
||||
|
||||
function Dashboard() {
|
||||
const path = usePath();
|
||||
const location = useLocation();
|
||||
const [load, setLoad] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!load) {
|
||||
path.update(location.pathname.substring(1, location.pathname.length));
|
||||
setLoad(true);
|
||||
}
|
||||
|
||||
const id = setInterval(() => {
|
||||
path.update(location.pathname.substring(1, location.pathname.length));
|
||||
}, 5000);
|
||||
|
||||
return () => clearInterval(id);
|
||||
}, [load, path, location]);
|
||||
|
||||
return (
|
||||
<Directory />
|
||||
);
|
||||
|
|
|
@ -1,17 +1,6 @@
|
|||
import { usePath } from "../../store/path";
|
||||
import { useEffect } from "react";
|
||||
|
||||
import "./directory.scss";
|
||||
|
||||
function Directory() {
|
||||
const path = usePath();
|
||||
|
||||
useEffect(() => {
|
||||
path.update(location.pathname);
|
||||
});
|
||||
|
||||
return (
|
||||
<div></div>
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
0
src/components/file-view/fview.scss
Normal file
0
src/components/file-view/fview.scss
Normal file
7
src/components/file-view/index.tsx
Normal file
7
src/components/file-view/index.tsx
Normal file
|
@ -0,0 +1,7 @@
|
|||
function FileView() {
|
||||
return (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
|
||||
export default FileView;
|
|
@ -1,14 +1,34 @@
|
|||
import { create } from "zustand";
|
||||
|
||||
interface PathState {
|
||||
data: undefined;
|
||||
data: PathResponse | string | undefined;
|
||||
update(path: string): Promise<void>;
|
||||
}
|
||||
|
||||
interface PathResponse {
|
||||
ok: number;
|
||||
path: string;
|
||||
entries: Array<DirEntry>
|
||||
}
|
||||
|
||||
export interface DirEntry {
|
||||
name: string;
|
||||
file_size: number;
|
||||
}
|
||||
|
||||
export const usePath = create<PathState>((set) => ({
|
||||
data: undefined,
|
||||
update: async (path: string) => {
|
||||
console.log(path);
|
||||
const res = await fetch(`/api/path/${path}`);
|
||||
if (res.status !== 200 && res.status !== 304) {
|
||||
set({ data: undefined });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
set({ data: await res.json() });
|
||||
} catch {
|
||||
set({ data: `/api/path/${path}` });
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
Loading…
Reference in a new issue