0.1.3 fb536a2

storeimages.go RawHistoryFolder

1package store
2
3import (
4	"fmt"
5	"io"
6	"os"
7	"path/filepath"
8	"sync"
9
10	"github.com/bnema/gordon/internal/common"
11	"github.com/google/uuid"
12)
13
14var (
15	imagePath string
16	mu        sync.Mutex
17)
18
19// setImagePath sets the image path in a thread-safe manner
20func setImagePath(path string) {
21	mu.Lock()
22	defer mu.Unlock()
23	imagePath = path
24}
25
26// getImagePath gets the image path in a thread-safe manner
27func getImagePath() string {
28	mu.Lock()
29	defer mu.Unlock()
30	return imagePath
31}
32
33func SaveImageToStorage(config *common.Config, originalFilename string, buf io.Reader) (string, error) {
34	// Ensure the images directory exists
35	imagesDir := filepath.Join(config.General.StorageDir, "images")
36	if err := os.MkdirAll(imagesDir, 0755); err != nil {
37		return "", fmt.Errorf("failed to create images directory: %v", err)
38	}
39
40	// Generate a unique ID for the image
41	id := uuid.New().String()
42
43	// Create a filename with the ID and original extension
44	ext := filepath.Ext(originalFilename)
45	filename := fmt.Sprintf("%s%s", id, ext)
46
47	// Full path for the new image
48	imagePath := filepath.Join(imagesDir, filename)
49
50	fmt.Printf("Saving image to: %s\n", imagePath)
51
52	// Create the file
53	outFile, err := os.Create(imagePath)
54	if err != nil {
55		return "", fmt.Errorf("failed to create file: %v", err)
56	}
57	defer outFile.Close()
58
59	// Write the content
60	written, err := io.Copy(outFile, buf)
61	if err != nil {
62		os.Remove(imagePath) // Clean up in case of error
63		return "", fmt.Errorf("failed to write file: %v", err)
64	}
65
66	fmt.Printf("Wrote %d bytes to %s\n", written, imagePath)
67
68	return imagePath, nil
69}
70
71func RemoveFromStorage(imagePath string) error {
72	if imagePath == "" {
73		return fmt.Errorf("no image path provided to remove")
74	}
75
76	fmt.Printf("Attempting to remove file: %s\n", imagePath)
77
78	err := os.Remove(imagePath)
79	if err != nil {
80		return fmt.Errorf("failed to remove file: %v", err)
81	}
82
83	fmt.Printf("Successfully removed file: %s\n", imagePath)
84
85	return nil
86}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close