mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
1 parent
bd8add89f3
commit
2e5241733a
2 files changed
+9
-11
No files matched your search
@@ -18,6 +18,7 @@ package webview
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -179,7 +180,7 @@ func (h *Host) call(ctx context.Context, name string, raw json.RawMessage) (any,
|
|||||||
engine.ReserveOutput = h.reserveOutput
|
engine.ReserveOutput = h.reserveOutput
|
||||||
engine.CleanupOutput = h.cleanupOutput
|
engine.CleanupOutput = h.cleanupOutput
|
||||||
engine.LoadFont = h.loadFont
|
engine.LoadFont = h.loadFont
|
||||||
id := token()
|
id := rand.Text()
|
||||||
h.mu.Lock()
|
h.mu.Lock()
|
||||||
h.engines[id] = engine
|
h.engines[id] = engine
|
||||||
h.mu.Unlock()
|
h.mu.Unlock()
|
||||||
|
|||||||
@@ -69,9 +69,6 @@ func newFileStore() (*fileStore, error) {
|
|||||||
return &fileStore{entries: make(map[string]*fileEntry), writers: make(map[string]*fileWriter), temporary: dir}, nil
|
return &fileStore{entries: make(map[string]*fileEntry), writers: make(map[string]*fileWriter), temporary: dir}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// token 生成不暴露本机路径的资源标识
|
|
||||||
func token() string { return rand.Text() }
|
|
||||||
|
|
||||||
// add 登记已有授权文件
|
// add 登记已有授权文件
|
||||||
func (s *fileStore) add(name string, directory bool) (map[string]any, error) {
|
func (s *fileStore) add(name string, directory bool) (map[string]any, error) {
|
||||||
info, err := os.Stat(name)
|
info, err := os.Stat(name)
|
||||||
@@ -83,7 +80,7 @@ func (s *fileStore) add(name string, directory bool) (map[string]any, error) {
|
|||||||
}
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
id := token()
|
id := rand.Text()
|
||||||
s.entries[id] = &fileEntry{path: name, name: filepath.Base(name), directory: directory}
|
s.entries[id] = &fileEntry{path: name, name: filepath.Base(name), directory: directory}
|
||||||
return s.descriptor(id), nil
|
return s.descriptor(id), nil
|
||||||
}
|
}
|
||||||
@@ -92,7 +89,7 @@ func (s *fileStore) add(name string, directory bool) (map[string]any, error) {
|
|||||||
func (s *fileStore) save(name string) map[string]any {
|
func (s *fileStore) save(name string) map[string]any {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
id := token()
|
id := rand.Text()
|
||||||
s.entries[id] = &fileEntry{path: name, name: filepath.Base(name)}
|
s.entries[id] = &fileEntry{path: name, name: filepath.Base(name)}
|
||||||
return s.descriptor(id)
|
return s.descriptor(id)
|
||||||
}
|
}
|
||||||
@@ -127,7 +124,7 @@ func (s *fileStore) file(id string) (map[string]any, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
size = info.Size()
|
size = info.Size()
|
||||||
id = token()
|
id = rand.Text()
|
||||||
entry = &fileEntry{path: entry.path, name: entry.name, file: file}
|
entry = &fileEntry{path: entry.path, name: entry.name, file: file}
|
||||||
s.entries[id] = entry
|
s.entries[id] = entry
|
||||||
}
|
}
|
||||||
@@ -166,7 +163,7 @@ func (s *fileStore) bytes(data []byte) map[string]any {
|
|||||||
}
|
}
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
id := token()
|
id := rand.Text()
|
||||||
s.entries[id] = &fileEntry{data: data, name: "data"}
|
s.entries[id] = &fileEntry{data: data, name: "data"}
|
||||||
return map[string]any{"nativeFile": id, "size": len(data), "name": "data", "url": "/__native/data/" + id, "temporary": true}
|
return map[string]any{"nativeFile": id, "size": len(data), "name": "data", "url": "/__native/data/" + id, "temporary": true}
|
||||||
}
|
}
|
||||||
@@ -228,7 +225,7 @@ func (s *fileStore) child(id, name string, directory, create bool) (map[string]a
|
|||||||
if info.IsDir() != directory {
|
if info.IsDir() != directory {
|
||||||
return nil, fmt.Errorf("文件类型不匹配")
|
return nil, fmt.Errorf("文件类型不匹配")
|
||||||
}
|
}
|
||||||
key := token()
|
key := rand.Text()
|
||||||
s.entries[key] = &fileEntry{path: filepath.Join(parent.path, name), name: name, directory: directory, owned: created}
|
s.entries[key] = &fileEntry{path: filepath.Join(parent.path, name), name: name, directory: directory, owned: created}
|
||||||
return s.descriptor(key), nil
|
return s.descriptor(key), nil
|
||||||
}
|
}
|
||||||
@@ -276,7 +273,7 @@ func (s *fileStore) reserve(id, base, extension string, directory bool) (string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
s.entries[token()] = &fileEntry{path: filepath.Join(parent.path, name), name: name, directory: directory, owned: true}
|
s.entries[rand.Text()] = &fileEntry{path: filepath.Join(parent.path, name), name: name, directory: directory, owned: true}
|
||||||
return stem, name, nil
|
return stem, name, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +293,7 @@ func (s *fileStore) begin(id string) (*fileWriter, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
writer := &fileWriter{id: token(), store: s, file: file, target: entry.path}
|
writer := &fileWriter{id: rand.Text(), store: s, file: file, target: entry.path}
|
||||||
s.writers[writer.id] = writer
|
s.writers[writer.id] = writer
|
||||||
return writer, nil
|
return writer, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user