feat: add SSO workspace, named shares and Debian release tooling

This commit is contained in:
SantaSpeen committed 2026-10-21 20:57:44 +03:00
1 parent 833d908884
commit 87bc33e675
106 files changed
+4160 -5637

No files matched your search

+18 -4
View File
@@ -6,8 +6,10 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/asdine/storm/v3"
"net/http"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
@@ -155,6 +157,8 @@ var shareDeleteHandler = withPermShare(func(_ http.ResponseWriter, r *http.Reque
return errToStatus(err), err
})
var shareKeyPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_-]{1,63}$`)
var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
// Only allow sharing paths that currently exist. Otherwise a share could be
// created for a non-existent path and would silently start exposing
@@ -170,26 +174,33 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
var s *share.Link
var body share.CreateBody
if r.Body != nil {
r.Body = http.MaxBytesReader(w, r.Body, 16<<10)
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
return http.StatusBadRequest, fmt.Errorf("failed to decode body: %w", err)
}
defer r.Body.Close()
}
bytes := make([]byte, 6)
bytes := make([]byte, 16)
_, err := rand.Read(bytes)
if err != nil {
return http.StatusInternalServerError, err
}
str := base64.URLEncoding.EncodeToString(bytes)
str := base64.RawURLEncoding.EncodeToString(bytes)
if body.Key != "" {
if !shareKeyPattern.MatchString(body.Key) {
return http.StatusBadRequest, errors.New("key must be 2–64 ASCII letters, digits, underscores or hyphens, starting with a letter or digit")
}
str = body.Key
}
var expire int64 = 0
if body.Expires != "" {
num, err := strconv.Atoi(body.Expires)
if err != nil {
return http.StatusInternalServerError, err
if err != nil || num < 0 || num > 36500 {
return http.StatusBadRequest, errors.New("invalid expiry: use 0–36500 units")
}
var add time.Duration
@@ -231,6 +242,9 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
}
if err := d.store.Share.Save(s); err != nil {
if errors.Is(err, storm.ErrAlreadyExists) {
return http.StatusConflict, errors.New("this short link name is already in use")
}
return http.StatusInternalServerError, err
}