0.1.1 96c369e

uploadcontainerimage.go RawHistoryFolder

1package handler
2
3import (
4	"bytes"
5	"fmt"
6	"io"
7	"net/http"
8
9	"github.com/bnema/gordon/internal/server"
10	"github.com/bnema/gordon/internal/templating/render"
11	"github.com/bnema/gordon/pkg/docker"
12	"github.com/bnema/gordon/pkg/store"
13	"github.com/labstack/echo/v4"
14)
15
16const MaxUploadSize = 1024 * 1024 * 1024 // 1GB
17
18// UploadImageHandler handles the /upload-image route to show the form
19func UploadImageGETHandler(c echo.Context, a *server.App) error {
20	data := map[string]interface{}{
21		"Title": "Upload Image",
22	}
23
24	rendererData, err := render.GetHTMLRenderer("html/fragments", "uploadimage.gohtml", a.TemplateFS, a)
25	if err != nil {
26		return sendError(c, err)
27	}
28
29	renderedHTML, err := rendererData.Render(data, a)
30	if err != nil {
31		return err
32	}
33	return c.HTML(200, renderedHTML)
34}
35
36// UploadImageHandler handles the /upload-image
37func UploadImagePOSTHandler(c echo.Context, a *server.App) error {
38	// Set upload size limit
39	c.Request().Body = http.MaxBytesReader(c.Response(), c.Request().Body, MaxUploadSize)
40	if err := c.Request().ParseMultipartForm(MaxUploadSize); err != nil {
41		return c.String(http.StatusRequestEntityTooLarge, "File size exceeded")
42	}
43
44	// Get the file from the form
45	file, header, err := c.Request().FormFile("file")
46	if err != nil {
47		return sendError(c, err)
48	}
49
50	// Get the file size
51	buf := new(bytes.Buffer)
52	_, err = io.Copy(buf, file)
53	if err != nil {
54		return sendError(c, err)
55	}
56
57	// Get the filename
58	filename := header.Filename
59
60	// Save the image to the storage directory
61	saveInPath, err := store.SaveImageToStorage(&a.Config, filename, buf)
62	if err != nil {
63		return sendError(c, err)
64	}
65
66	// Import the image into Docker
67	err = docker.ImportImageToEngine(saveInPath)
68	if err != nil {
69		return fmt.Errorf("failed to import image to Docker: %v", err)
70	}
71
72	// Remove the image from the storage directory
73	err = store.RemoveFromStorage()
74	if err != nil {
75		return sendError(c, err)
76	}
77
78	return c.HTML(http.StatusOK, ActionSuccess(a))
79}

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