From 20e3466f2f293ccff0126d8cecbbeb68b0616879 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 8 Aug 2025 00:04:07 +0200 Subject: [PATCH] Templating --- controllers/index.go | 2 +- main.go | 2 +- views/index.html | 400 +---------------------------- views/layout.html | 298 +++++++++++++++++++++ views/partials/api-endpoints.html | 35 +++ views/partials/changelog.html | 15 ++ views/partials/header.html | 6 + views/partials/storage-info.html | 16 ++ views/partials/usage-examples.html | 26 ++ 9 files changed, 407 insertions(+), 393 deletions(-) create mode 100644 views/layout.html create mode 100644 views/partials/api-endpoints.html create mode 100644 views/partials/changelog.html create mode 100644 views/partials/header.html create mode 100644 views/partials/storage-info.html create mode 100644 views/partials/usage-examples.html diff --git a/controllers/index.go b/controllers/index.go index 01cd29e..a5fc36b 100644 --- a/controllers/index.go +++ b/controllers/index.go @@ -12,5 +12,5 @@ func HandleIndex(c *gin.Context) { if baseURL == "" { baseURL = "http://localhost:8080" } - c.HTML(http.StatusOK, "index.html", gin.H{"BaseURL": baseURL}) + c.HTML(http.StatusOK, "layout.html", gin.H{"BaseURL": baseURL, "Title": "Home"}) } diff --git a/main.go b/main.go index f6af0aa..790d320 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ func main() { r := gin.Default() - tmpl := template.Must(template.New("").ParseFS(viewsFS, "views/*.html")) + tmpl := template.Must(template.New("").ParseFS(viewsFS, "views/*.html", "views/partials/*.html")) r.SetHTMLTemplate(tmpl) r.GET("/", controllers.HandleIndex) diff --git a/views/index.html b/views/index.html index a83590d..9da438e 100644 --- a/views/index.html +++ b/views/index.html @@ -1,391 +1,9 @@ - - - - - - FITRA - File transfer API - - - - - -
-

🚀 FITRA - File transfer API

-
Version 1.0.0
-

Simple file upload and download service for developers using HTTP requests in CLI.

-

Contact me on Matrix: @root@adhd.sh or via Discord: nu11ed

- -
-

💾 Todays storage usage

-

- This resets after 24h -

-
-
-
-
- Loading... - Loading... - Loading... -
-
- -

📋 API endpoints

- -
- -

POST/upload

-

Description: Upload a file

-

cURL example:

-
curl -X POST -F "file=@/path/to/your/file.txt" {{.BaseURL}}/upload
-
- -
- -

GET/uploads/{fileID}/{filename}

-

Description: Download a file using the ID and filename from upload response

-

cURL example:

-
curl -O {{.BaseURL}}/uploads/{fileID}/{filename}
-
- -
- -

GET/storage

-

Description: Check storage usage and capacity

-

cURL example:

-
curl {{.BaseURL}}/storage
-
- -
- -

GET/health

-

Description: Check service health

-

cURL example:

-
curl {{.BaseURL}}/health
-
- -

🔄 Usage

-
- Step 1: Upload a file using POST /upload with form-data 'file' parameter -
-
- Step 2: Use the returned 'id' and 'filename' to construct download URL -
-
- Step 3: Download the file using GET /uploads/{id}/{filename} -
- -

💡 Examples

-
# 1. Upload a file
-curl -X POST -F "file=@myfile.txt" {{.BaseURL}}/upload
-
-# Response will include:
-# {
-#   "id": "abc123...",
-#   "filename": "myfile.txt",
-#   "url": "{{.BaseURL}}/uploads/abc123.../myfile.txt"
-# }
-
-# 2. Download the file
-curl -O {{.BaseURL}}/uploads/abc123.../myfile.txt
-
- -
-
-

📝 Changelog

- -
-
v1.0.0
-
2024-12-01
-
    -
  • Initial release
  • -
-
-
-
- - - - \ No newline at end of file +{{define "content"}} +
+ {{template "header" .}} + {{template "storage-info" .}} + {{template "api-endpoints" .}} + {{template "usage-examples" .}} +
+{{template "changelog" .}} +{{end}} \ No newline at end of file diff --git a/views/layout.html b/views/layout.html new file mode 100644 index 0000000..fab66e8 --- /dev/null +++ b/views/layout.html @@ -0,0 +1,298 @@ + + + + + + {{.Title}} - FITRA - File transfer API + + + + + + {{block "content" .}}{{end}} + + + + \ No newline at end of file diff --git a/views/partials/api-endpoints.html b/views/partials/api-endpoints.html new file mode 100644 index 0000000..6e975f3 --- /dev/null +++ b/views/partials/api-endpoints.html @@ -0,0 +1,35 @@ +{{define "api-endpoints"}} +

📋 API endpoints

+ +
+ +

POST/upload

+

Description: Upload a file

+

cURL example:

+
curl -X POST -F "file=@/path/to/your/file.txt" {{.BaseURL}}/upload
+
+ +
+ +

GET/uploads/{fileID}/{filename}

+

Description: Download a file using the ID and filename from upload response

+

cURL example:

+
curl -O {{.BaseURL}}/uploads/{fileID}/{filename}
+
+ +
+ +

GET/storage

+

Description: Check storage usage and capacity

+

cURL example:

+
curl {{.BaseURL}}/storage
+
+ +
+ +

GET/health

+

Description: Check service health

+

cURL example:

+
curl {{.BaseURL}}/health
+
+{{end}} \ No newline at end of file diff --git a/views/partials/changelog.html b/views/partials/changelog.html new file mode 100644 index 0000000..44bafd7 --- /dev/null +++ b/views/partials/changelog.html @@ -0,0 +1,15 @@ +{{define "changelog"}} +
+
+

📝 Changelog

+ +
+
v1.0.0
+
2024-12-01
+
    +
  • Initial release
  • +
+
+
+
+{{end}} \ No newline at end of file diff --git a/views/partials/header.html b/views/partials/header.html new file mode 100644 index 0000000..1925489 --- /dev/null +++ b/views/partials/header.html @@ -0,0 +1,6 @@ +{{define "header"}} +

🚀 FITRA - File transfer API

+
Version 1.0.0
+

Simple file upload and download service for developers using HTTP requests in CLI.

+

Contact me on Matrix: @root@adhd.sh or via Discord: nu11ed

+{{end}} \ No newline at end of file diff --git a/views/partials/storage-info.html b/views/partials/storage-info.html new file mode 100644 index 0000000..361f5da --- /dev/null +++ b/views/partials/storage-info.html @@ -0,0 +1,16 @@ +{{define "storage-info"}} +
+

💾 Todays storage usage

+

+ This resets after 24h +

+
+
+
+
+ Loading... + Loading... + Loading... +
+
+{{end}} \ No newline at end of file diff --git a/views/partials/usage-examples.html b/views/partials/usage-examples.html new file mode 100644 index 0000000..2f2444e --- /dev/null +++ b/views/partials/usage-examples.html @@ -0,0 +1,26 @@ +{{define "usage-examples"}} +

🔄 Usage

+
+ Step 1: Upload a file using POST /upload with form-data 'file' parameter +
+
+ Step 2: Use the returned 'id' and 'filename' to construct download URL +
+
+ Step 3: Download the file using GET /uploads/{id}/{filename} +
+ +

💡 Examples

+
# 1. Upload a file
+curl -X POST -F "file=@myfile.txt" {{.BaseURL}}/upload
+
+# Response will include:
+# {
+#   "id": "abc123...",
+#   "filename": "myfile.txt",
+#   "url": "{{.BaseURL}}/uploads/abc123.../myfile.txt"
+# }
+
+# 2. Download the file
+curl -O {{.BaseURL}}/uploads/abc123.../myfile.txt
+{{end}} \ No newline at end of file