-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiles_api.go
More file actions
161 lines (141 loc) · 4.76 KB
/
files_api.go
File metadata and controls
161 lines (141 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright (c) 2026 threatvec & talkdedsec. All Rights Reserved.
// This software is proprietary and confidential.
package main
import (
"context"
"encoding/base64"
"encoding/json"
"os"
"time"
"vaultx/internal/files"
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
)
// OpenFileDialog opens a native file picker for documents and returns the selected path.
func (a *App) OpenFileDialog(title string) (string, error) {
return wailsRuntime.OpenFileDialog(a.ctx, wailsRuntime.OpenDialogOptions{
Title: title,
Filters: []wailsRuntime.FileFilter{
{DisplayName: "All Supported Files", Pattern: "*.pdf;*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.jpg;*.jpeg;*.png;*.gif;*.tiff;*.tif;*.webp"},
{DisplayName: "PDF Files", Pattern: "*.pdf"},
{DisplayName: "Office Documents", Pattern: "*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx"},
{DisplayName: "Images", Pattern: "*.jpg;*.jpeg;*.png;*.gif;*.tiff;*.tif;*.webp"},
{DisplayName: "All Files", Pattern: "*"},
},
})
}
// OpenImageDialog opens a native file picker for images only.
func (a *App) OpenImageDialog(title string) (string, error) {
return wailsRuntime.OpenFileDialog(a.ctx, wailsRuntime.OpenDialogOptions{
Title: title,
Filters: []wailsRuntime.FileFilter{
{DisplayName: "Images", Pattern: "*.jpg;*.jpeg;*.png;*.gif;*.tiff;*.tif;*.webp;*.bmp"},
{DisplayName: "All Files", Pattern: "*"},
},
})
}
// OpenAnyFileDialog opens a native file picker with no filter.
func (a *App) OpenAnyFileDialog(title string) (string, error) {
return wailsRuntime.OpenFileDialog(a.ctx, wailsRuntime.OpenDialogOptions{
Title: title,
Filters: []wailsRuntime.FileFilter{
{DisplayName: "All Files", Pattern: "*"},
},
})
}
// ExtractFileMetadata extracts metadata from any supported file type.
func (a *App) ExtractFileMetadata(filePath string) (*files.MetadataResult, error) {
result, err := files.ExtractMetadata(filePath)
if err != nil {
return nil, err
}
if a.db != nil {
raw, _ := json.Marshal(result)
a.db.SaveQueryHistory("metadata", filePath, string(raw))
}
return result, nil
}
// ExtractImageEXIF extracts EXIF data from an image file.
func (a *App) ExtractImageEXIF(filePath string) (*files.EXIFResult, error) {
result, err := files.ExtractEXIFFromPath(filePath)
if err != nil {
return nil, err
}
if a.db != nil {
raw, _ := json.Marshal(result)
a.db.SaveQueryHistory("imageexif", filePath, string(raw))
}
return result, nil
}
// LookupHashVT looks up a file hash on VirusTotal.
func (a *App) LookupHashVT(hash string) (*files.HashLookupResult, error) {
ctx, cancel := context.WithTimeout(a.ctx, 25*time.Second)
defer cancel()
var vtKey string
if a.db != nil {
settings, _ := a.db.GetAllSettings()
vtKey = settings["virustotal_api_key"]
}
result, err := files.LookupHashVT(ctx, hash, vtKey)
if err != nil {
return nil, err
}
if a.db != nil {
raw, _ := json.Marshal(result)
a.db.SaveQueryHistory("hashlookup", hash, string(raw))
}
return result, nil
}
// HashFileVT computes a file's SHA256 and looks it up on VirusTotal.
func (a *App) HashFileVT(filePath string) (*files.HashLookupResult, error) {
hashSet := files.HashFile(filePath)
if hashSet.Error != "" {
return &files.HashLookupResult{Error: hashSet.Error}, nil
}
return a.LookupHashVT(hashSet.SHA256)
}
// HashText computes MD5/SHA1/SHA256/SHA512 of a text string.
func (a *App) HashText(text string) *files.HashSet {
return files.HashText(text)
}
// HashFilePath computes MD5/SHA1/SHA256/SHA512 of a file.
func (a *App) HashFilePath(filePath string) *files.HashSet {
return files.HashFile(filePath)
}
// CompareHashes checks if two hash strings match.
func (a *App) CompareHashes(hashA, hashB string) *files.CompareResult {
return files.CompareHashes(hashA, hashB)
}
// DecodeQR decodes a QR code from an image file path.
func (a *App) DecodeQR(filePath string) (*files.QRResult, error) {
ctx, cancel := context.WithTimeout(a.ctx, 20*time.Second)
defer cancel()
result, err := files.DecodeQR(ctx, filePath)
if err != nil {
return nil, err
}
if a.db != nil {
raw, _ := json.Marshal(result)
a.db.SaveQueryHistory("qranalyzer", filePath, string(raw))
}
return result, nil
}
// AnalyzeDocument performs deep security analysis on a document file.
func (a *App) AnalyzeDocument(filePath string) (*files.DocumentAnalysisResult, error) {
result, err := files.AnalyzeDocument(filePath)
if err != nil {
return nil, err
}
if a.db != nil {
raw, _ := json.Marshal(result)
a.db.SaveQueryHistory("documentanalyzer", filePath, string(raw))
}
return result, nil
}
// ReadFileAsBase64 reads a file and returns base64-encoded content (for image preview).
func (a *App) ReadFileAsBase64(filePath string) (string, error) {
data, err := os.ReadFile(filePath)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(data), nil
}