Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
424eb12
Refactoring, added request url
Forceu Jul 28, 2025
55ded88
Merge branch 'master' into guestupload
Forceu Sep 7, 2025
0826a01
Merge branch 'master' into guestupload
Forceu Nov 5, 2025
d3aee21
Added migration for new file request user permission, added permissio…
Forceu Dec 1, 2025
0b00d5a
Make user permission buttons dynamic for new user instead of hard cod…
Forceu Dec 1, 2025
862e3c0
Merge branch 'master' into guestupload
Forceu Dec 1, 2025
0872801
Added API permission PERM_MANAGE_FILE_REQUESTS
Forceu Dec 1, 2025
90e6060
Merge branch 'master' into guestupload
Forceu Dec 4, 2025
60fd353
Fixed API button UI/JS
Forceu Dec 4, 2025
dc7d9e6
Added database table operation for file requests, added basic overvie…
Forceu Dec 12, 2025
b8f13d4
Populate info on overview, disallow regular download, sort requests
Forceu Dec 13, 2025
0399740
Don't allow downloads with hotlink URLs, reordered header menu, impro…
Forceu Dec 13, 2025
decd5cb
Added api/filerequest/delete and possibly fixed /e2e/set call
Forceu Dec 16, 2025
8d23de5
Implementation of delete button, possible fix /e2e/set?
Forceu Dec 17, 2025
1690e17
Refactoring, clean api keys and file requests with invalid users, mak…
Forceu Dec 19, 2025
185cdd6
Merge branch 'master' into guestupload
Forceu Dec 20, 2025
1817bf7
Changed admin JS version to 15 to avoid conflicts
Forceu Dec 20, 2025
5fa7d04
Fixed sqlite upgrade
Forceu Dec 20, 2025
ee92156
Fix UI and JS
Forceu Dec 21, 2025
77f9986
Delete or migrate file request when user is deleted
Forceu Dec 27, 2025
cfd3c64
Add modal for creating / editing file requests (not functional yet)
Forceu Dec 27, 2025
23dad2c
Change db version to 12
Forceu Dec 29, 2025
e8ef6f5
Merge branch 'master' into guestupload
Forceu Dec 29, 2025
e8f5601
Use browser TZ for file request times
Forceu Dec 29, 2025
5d10d5d
Added Total size column, display max files in table as well
Forceu Dec 29, 2025
9e8a4b1
Added API call to edit and create file requests, improved openapi
Forceu Dec 29, 2025
30539b8
Added API call for listing file requests, fixed errors in openapi.json
Forceu Dec 29, 2025
5c60acc
Formatting
Forceu Dec 29, 2025
240b2b6
Save defaults for new FR (date not working yet), copied openapi.json
Forceu Dec 29, 2025
873682e
Working date picker, formatting
Forceu Dec 29, 2025
c31b147
Working version for creating and editing requests
Forceu Dec 29, 2025
03fa4c2
Working add/update UI for file requests
Forceu Dec 29, 2025
54c771b
Add API call to download files and optionally not increasing counter,…
Forceu Dec 30, 2025
25a3b87
Added option for presigned URLs and add download button in main menu
Forceu Dec 30, 2025
701130a
Don't allow download for e2e encrypted files
Forceu Dec 30, 2025
86ba188
Added file IDs to API UR output, added autocomplete hint to login form
Forceu Dec 30, 2025
25ab29b
Working download if only one file is uploaded to file request, indica…
Forceu Dec 30, 2025
b9e86a6
Working implementation of zipping files, add base64 decoding for head…
Forceu Dec 31, 2025
571e018
Download all working now in UI
Forceu Dec 31, 2025
de4b483
Add logging for file requests
Forceu Dec 31, 2025
f80f49e
Merge branch 'master' into guestupload
Forceu Dec 31, 2025
94b822f
Create api key for new file request, don't allow file request api key…
Forceu Jan 1, 2026
49aaa99
Merge branch 'master' into guestupload
Forceu Jan 1, 2026
4500d04
Fixed creation date not being saved for file request, updated openapi
Forceu Jan 1, 2026
260bbab
Refactoring
Forceu Jan 1, 2026
bc0afcf
Refactoring, fixed GetAll() not populating files, added placeholder f…
Forceu Jan 2, 2026
b61d914
Working file list for file requests
Forceu Jan 2, 2026
70917e2
Fixed file request expiry defaults
Forceu Jan 2, 2026
20fc632
Improved file view ui
Forceu Jan 2, 2026
f3905e3
Merge branch 'master' into guestupload
Forceu Jan 2, 2026
4a2abde
Merge branch 'master' into guestupload
Forceu Jan 2, 2026
c21a4f5
Changed file request ID to string type, updated openapi
Forceu Jan 3, 2026
cc59fff
Implemented API calls for uploading files as file request
Forceu Jan 6, 2026
3fad4c2
First working prototype
Forceu Jan 6, 2026
c4f5a1e
Check for max file count and expiry
Forceu Jan 6, 2026
c87c23f
Add URL to JS on new file request, fixed race condition
Forceu Jan 6, 2026
315fb51
Merge branch 'master' into guestupload
Forceu Jan 6, 2026
b314fa3
Fixed logs for file requests and fixed some tests
Forceu Jan 6, 2026
de36c1b
Fixed JSON output for chunkcomplete, fixed tests
Forceu Jan 6, 2026
f315b3b
Fixed tests
Forceu Jan 6, 2026
96f975d
Refactoring JS, adding note for upload requests, better view for publ…
Forceu Jan 7, 2026
3a9639f
Show icon button for expanding instead of clickable file number, add …
Forceu Jan 7, 2026
3a79f40
Add delete button for files to be uploaded
Forceu Jan 7, 2026
bd8385b
Merge branch 'master' into guestupload
Forceu Jan 12, 2026
f464ecb
Merge branch 'master' into guestupload
Forceu Jan 12, 2026
421e254
Merge branch 'master' into guestupload
Forceu Jan 12, 2026
725d264
Fixed DB upgrade, working prototype for upload page
Forceu Jan 12, 2026
3944206
Merge branch 'master' into guestupload
Forceu Jan 14, 2026
4d66e5c
Merge branch 'master' into guestupload
Forceu Jan 14, 2026
867dbd6
Change api name
Forceu Jan 14, 2026
00b82b9
Added chunk reservation system for public uploads, fixed openapi
Forceu Jan 15, 2026
c0f1abd
Fixed tests
Forceu Jan 15, 2026
0a2ca7f
Add download option for gokapi-cli, TODO: error on e2e
Forceu Jan 18, 2026
335f204
Remove file after upload if requested, output json result
Forceu Jan 19, 2026
15af392
Better error page
Forceu Jan 19, 2026
7ab8bfc
Changed wording, fixed tests
Forceu Jan 19, 2026
424e48f
Breaking: Check that chunks are at least 5MB, added rate limmiting fo…
Forceu Jan 22, 2026
548cd62
Refactoring: Make environment variable private
Forceu Jan 23, 2026
c3cf344
Check that env can only be positive, add UR limites for non-admin use…
Forceu Jan 24, 2026
25d6c04
Merge branch 'master' into guestupload
Forceu Jan 24, 2026
0757f19
Merge branch 'master' into guestupload
Forceu Jan 24, 2026
c8f8135
Added documentation
Forceu Jan 24, 2026
920e800
Added errorCodes in API output
Forceu Jan 25, 2026
72d4ff8
Fixed tests
Forceu Jan 25, 2026
a01dff6
Add re-try and proper error messages
Forceu Jan 25, 2026
dcc781e
Align upload bar, fixed API specs, allow upload of 0B files
Forceu Jan 25, 2026
10b5b45
Only enable upload button with uploadable files, restore upload bar o…
Forceu Jan 25, 2026
581bf5d
Better logging for uploads to file request
Forceu Jan 25, 2026
4a0fae5
Implement decryption of cloud storage files for download
Forceu Jan 26, 2026
d49ccd6
Fixed openapi specs, show error when -i is not passed to gokapi-cli, …
Forceu Jan 26, 2026
cd924a6
Add API call to remove UUID reservation for cancelled or failed uploads
Forceu Jan 26, 2026
afb1423
Added drag&drop and paste function
Forceu Jan 26, 2026
a9da3f8
Retry on status 429 for 60 seconds, refactoring and formatting
Forceu Jan 26, 2026
8c17325
Set box shadow to all sites, prevent scrolling
Forceu Jan 26, 2026
8e110b6
Added docs
Forceu Jan 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/go-generate/minifyStaticContent.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ func fileExists(filename string) bool {
// Auto-generated content below, do not modify
// Version codes can be changed in updateVersionNumbers.go

const jsAdminVersion = 13
const jsAdminVersion = 14
const jsE2EVersion = 8
const cssMainVersion = 5
2 changes: 1 addition & 1 deletion build/go-generate/updateVersionNumbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"strings"
)

const versionJsAdmin = 13
const versionJsAdmin = 14
const versionJsDropzone = 5
const versionJsE2EAdmin = 8
const versionCssMain = 5
Expand Down
1 change: 1 addition & 0 deletions internal/configuration/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func Load() {
serverSettings.MinLengthPassword = Environment.MinLengthPassword
serverSettings.LengthId = Environment.LengthId
serverSettings.LengthHotlinkId = Environment.LengthHotlinkId
serverSettings.AllowGuestUploadsByDefault = Environment.PermRequestGrantedByDefault
helper.CreateDir(serverSettings.DataDir)
filesystem.Init(serverSettings.DataDir)
logging.Init(Environment.DataDir)
Expand Down
17 changes: 16 additions & 1 deletion internal/configuration/database/provider/redis/Redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis
import (
"errors"
"fmt"
"github.com/forceu/gokapi/internal/environment"
"github.com/forceu/gokapi/internal/helper"
"github.com/forceu/gokapi/internal/models"
redigo "github.com/gomodule/redigo/redis"
Expand All @@ -19,7 +20,7 @@ type DatabaseProvider struct {
}

// DatabaseSchemeVersion contains the version number to be expected from the current database. If lower, an upgrade will be performed
const DatabaseSchemeVersion = 5
const DatabaseSchemeVersion = 6

// New returns an instance
func New(dbConfig models.DbConnection) (DatabaseProvider, error) {
Expand Down Expand Up @@ -99,6 +100,20 @@ func (p DatabaseProvider) Upgrade(currentDbVersion int) {
osExit(1)
return
}
// pre multi-user
if currentDbVersion < 6 {
if environment.New().PermRequestGrantedByDefault {
for _, user := range p.GetAllUsers() {
user.GrantPermission(models.UserPermGuestUploads)
p.SaveUser(user, false)
}
}
for _, apiKey := range p.GetAllApiKeys() {
if apiKey.IsSystemKey {
p.DeleteApiKey(apiKey.Id)
}
}
}
}

const keyDbVersion = "dbversion"
Expand Down
17 changes: 16 additions & 1 deletion internal/configuration/database/provider/sqlite/Sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/forceu/gokapi/internal/environment"
"os"
"path/filepath"

Expand All @@ -19,7 +20,7 @@ type DatabaseProvider struct {
}

// DatabaseSchemeVersion contains the version number to be expected from the current database. If lower, an upgrade will be performed
const DatabaseSchemeVersion = 10
const DatabaseSchemeVersion = 11

// New returns an instance
func New(dbConfig models.DbConnection) (DatabaseProvider, error) {
Expand All @@ -39,6 +40,20 @@ func (p DatabaseProvider) Upgrade(currentDbVersion int) {
osExit(1)
return
}
// pre multi-user
if currentDbVersion < 11 {
if environment.New().PermRequestGrantedByDefault {
for _, user := range p.GetAllUsers() {
user.GrantPermission(models.UserPermGuestUploads)
p.SaveUser(user, false)
}
}
for _, apiKey := range p.GetAllApiKeys() {
if apiKey.IsSystemKey {
p.DeleteApiKey(apiKey.Id)
}
}
}
}

// GetDbVersion gets the version number of the database
Expand Down
43 changes: 22 additions & 21 deletions internal/environment/Environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,28 @@ const DefaultPort = 53842

// Environment is a struct containing available env variables
type Environment struct {
ConfigDir string `env:"CONFIG_DIR" envDefault:"config"`
ConfigFile string `env:"CONFIG_FILE" envDefault:"config.json"`
ConfigPath string
DataDir string `env:"DATA_DIR" envDefault:"data"`
ChunkSizeMB int `env:"CHUNK_SIZE_MB" envDefault:"45"`
LengthId int `env:"LENGTH_ID" envDefault:"15"`
LengthHotlinkId int `env:"LENGTH_HOTLINK_ID" envDefault:"40"`
MaxFileSize int `env:"MAX_FILESIZE" envDefault:"102400"` // 102400==100GB
MaxMemory int `env:"MAX_MEMORY_UPLOAD" envDefault:"50"`
MaxParallelUploads int `env:"MAX_PARALLEL_UPLOADS" envDefault:"3"`
WebserverPort int `env:"PORT" envDefault:"53842"`
MinLengthPassword int `env:"MIN_LENGTH_PASSWORD" envDefault:"8"`
DisableCorsCheck bool `env:"DISABLE_CORS_CHECK" envDefault:"false"`
LogToStdout bool `env:"LOG_STDOUT" envDefault:"false"`
HotlinkVideos bool `env:"ENABLE_HOTLINK_VIDEOS" envDefault:"false"`
AwsBucket string `env:"AWS_BUCKET"`
AwsRegion string `env:"AWS_REGION"`
AwsKeyId string `env:"AWS_KEY"`
AwsKeySecret string `env:"AWS_KEY_SECRET"`
AwsEndpoint string `env:"AWS_ENDPOINT"`
ActiveDeprecations []deprecation.Deprecation
ConfigDir string `env:"CONFIG_DIR" envDefault:"config"`
ConfigFile string `env:"CONFIG_FILE" envDefault:"config.json"`
ConfigPath string
DataDir string `env:"DATA_DIR" envDefault:"data"`
ChunkSizeMB int `env:"CHUNK_SIZE_MB" envDefault:"45"`
LengthId int `env:"LENGTH_ID" envDefault:"15"`
LengthHotlinkId int `env:"LENGTH_HOTLINK_ID" envDefault:"40"`
MaxFileSize int `env:"MAX_FILESIZE" envDefault:"102400"` // 102400==100GB
MaxMemory int `env:"MAX_MEMORY_UPLOAD" envDefault:"50"`
MaxParallelUploads int `env:"MAX_PARALLEL_UPLOADS" envDefault:"3"`
WebserverPort int `env:"PORT" envDefault:"53842"`
MinLengthPassword int `env:"MIN_LENGTH_PASSWORD" envDefault:"8"`
DisableCorsCheck bool `env:"DISABLE_CORS_CHECK" envDefault:"false"`
LogToStdout bool `env:"LOG_STDOUT" envDefault:"false"`
HotlinkVideos bool `env:"ENABLE_HOTLINK_VIDEOS" envDefault:"false"`
PermRequestGrantedByDefault bool `env:"ALLOW_GUEST_UPLOADS_BY_DEFAULT" envDefault:"false"`
AwsBucket string `env:"AWS_BUCKET"`
AwsRegion string `env:"AWS_REGION"`
AwsKeyId string `env:"AWS_KEY"`
AwsKeySecret string `env:"AWS_KEY_SECRET"`
AwsEndpoint string `env:"AWS_ENDPOINT"`
ActiveDeprecations []deprecation.Deprecation
}

// New parses the env variables
Expand Down
17 changes: 12 additions & 5 deletions internal/models/ApiKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ const (
ApiPermManageUsers
// ApiPermManageLogs is the permission required for managing the log file
ApiPermManageLogs
// ApiManageFileRequests is the permission required for creating and managing file requests
ApiManageFileRequests
)

// ApiPermNone means no permission granted
const ApiPermNone ApiPermission = 0

// ApiPermAll means all permission granted
const ApiPermAll ApiPermission = 255
const ApiPermAll ApiPermission = 511

// ApiPermDefault means all permission granted, except ApiPermApiMod, ApiPermManageUsers, ApiPermManageLogs and ApiPermReplace
// This is the default for new API keys that are created from the UI
const ApiPermDefault = ApiPermAll - ApiPermApiMod - ApiPermManageUsers - ApiPermReplace - ApiPermManageLogs
const ApiPermDefault = ApiPermAll - ApiPermApiMod - ApiPermManageUsers - ApiPermReplace - ApiPermManageLogs - ApiManageFileRequests

// ApiKey contains data of a single api key
type ApiKey struct {
Expand All @@ -45,8 +47,8 @@ type ApiKey struct {
UserId int `json:"UserId" redis:"UserId"`
}

// ApiPermission contains zero or more permissions as an uint8 format
type ApiPermission uint8
// ApiPermission contains zero or more permissions as an uint16 format
type ApiPermission uint16

// GetReadableDate returns the date as YYYY-MM-DD HH:MM:SS
func (key *ApiKey) GetReadableDate() string {
Expand Down Expand Up @@ -119,7 +121,12 @@ func (key *ApiKey) HasPermissionManageLogs() bool {
return key.HasPermission(ApiPermManageLogs)
}

// ApiKeyOutput is the output that is used after a new key is created
// HasPermissionManageFileRequests returns true if ApiManageFileRequests is granted
func (key *ApiKey) HasPermissionManageFileRequests() bool {
return key.HasPermission(ApiManageFileRequests)
}

// ApiKeyOutput is the output used after a new key is created
type ApiKeyOutput struct {
Result string
Id string
Expand Down
1 change: 1 addition & 0 deletions internal/models/Configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Configuration struct {
PicturesAlwaysLocal bool `json:"PicturesAlwaysLocal"`
SaveIp bool `json:"SaveIp"`
IncludeFilename bool `json:"IncludeFilename"`
AllowGuestUploadsByDefault bool `json:"-"`
}

// Encryption hold information about the encryption used on this file
Expand Down
17 changes: 12 additions & 5 deletions internal/models/User.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (u *User) GetReadableUserLevel() string {
}
}

// ToJson returns the user as a JSon object
// ToJson returns the user as a JSON object
func (u *User) ToJson() string {
result, err := json.Marshal(u)
helper.Check(err)
Expand All @@ -61,7 +61,7 @@ const UserLevelAdmin UserRank = 1
// UserLevelUser indicates that this user has only basic permissions by default
const UserLevelUser UserRank = 2

// UserRank indicates the rank that is assigned to the user
// UserRank indicates the rank assigned to the user
type UserRank uint8

// IsSuperAdmin returns true if the user has the Rank UserLevelSuperAdmin
Expand All @@ -75,9 +75,9 @@ func (u *User) IsSameUser(userId int) bool {
}

const (
// UserPermReplaceUploads allows to replace uploads
// UserPermReplaceUploads allows replacing uploads
UserPermReplaceUploads UserPermission = 1 << iota
// UserPermListOtherUploads allows to also list uploads by other users
// UserPermListOtherUploads allows also listing uploads by other users
UserPermListOtherUploads
// UserPermEditOtherUploads allows editing of uploads by other users
UserPermEditOtherUploads
Expand All @@ -91,13 +91,15 @@ const (
UserPermManageApiKeys
// UserPermManageUsers allows creating and editing of users, including granting and revoking permissions
UserPermManageUsers
// UserPermGuestUploads allows creating file requests
UserPermGuestUploads
)

// UserPermissionNone means that the user has no permissions
const UserPermissionNone UserPermission = 0

// UserPermissionAll means that the user has all permissions
const UserPermissionAll UserPermission = 255
const UserPermissionAll UserPermission = 511

// GrantPermission grants one or more permissions
func (u *User) GrantPermission(permission UserPermission) {
Expand Down Expand Up @@ -156,3 +158,8 @@ func (u *User) HasPermissionManageApi() bool {
func (u *User) HasPermissionManageUsers() bool {
return u.HasPermission(UserPermManageUsers)
}

// HasPermissionCreateFileRequests returns true if the user has the permission UserPermGuestUploads
func (u *User) HasPermissionCreateFileRequests() bool {
return u.HasPermission(UserPermGuestUploads)
}
37 changes: 18 additions & 19 deletions internal/webserver/api/Api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/forceu/gokapi/internal/logging"
"github.com/forceu/gokapi/internal/models"
"github.com/forceu/gokapi/internal/storage"
"github.com/forceu/gokapi/internal/webserver/authentication/users"
"github.com/forceu/gokapi/internal/webserver/fileupload"
"io"
"net/http"
Expand All @@ -19,7 +20,6 @@ import (

const lengthPublicId = 35
const lengthApiKey = 30
const minLengthUser = 2

// Process parses the request and executes the API call or returns an error message to the sender
func Process(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -214,6 +214,11 @@ func apiModifyApiKey(w http.ResponseWriter, r requestParser, user models.User) {
sendError(w, http.StatusUnauthorized, "Insufficient user permission for owner to set this API permission")
return
}
case models.ApiManageFileRequests:
if !apiKeyOwner.HasPermissionCreateFileRequests() {
sendError(w, http.StatusUnauthorized, "Insufficient user permission for owner to set this API permission")
return
}
default:
// do nothing
}
Expand Down Expand Up @@ -269,24 +274,16 @@ func apiCreateUser(w http.ResponseWriter, r requestParser, user models.User) {
if !ok {
panic("invalid parameter passed")
}
if len(request.Username) < minLengthUser {
sendError(w, http.StatusBadRequest, "Invalid username provided.")
return
}
_, ok = database.GetUserByName(request.Username)
if ok {
sendError(w, http.StatusConflict, "User already exists.")
return
}
newUser := models.User{
Name: request.Username,
UserLevel: models.UserLevelUser,
}
database.SaveUser(newUser, true)
newUser, ok = database.GetUserByName(request.Username)
if !ok {
sendError(w, http.StatusInternalServerError, "Could not save user")
return
newUser, err := users.Create(request.Username)
if err != nil {
switch {
case errors.Is(err, users.ErrorNameToShort):
sendError(w, http.StatusBadRequest, "Invalid username provided.")
case errors.Is(err, users.ErrorUserExists):
sendError(w, http.StatusConflict, "User already exists.")
default:
sendError(w, http.StatusInternalServerError, err.Error())
}
}
logging.LogUserCreation(newUser, user)
_, _ = w.Write([]byte(newUser.ToJson()))
Expand Down Expand Up @@ -676,6 +673,8 @@ func updateApiKeyPermsOnUserPermChange(userId int, userPerm models.UserPermissio
affectedPermission = models.ApiPermReplace
case models.UserPermManageLogs:
affectedPermission = models.ApiPermManageLogs
case models.UserPermGuestUploads:
affectedPermission = models.ApiManageFileRequests
default:
return
}
Expand Down
4 changes: 4 additions & 0 deletions internal/webserver/api/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ func (p *paramAuthModify) ProcessParameter(_ *http.Request) error {
p.Permission = models.ApiPermManageUsers
case "PERM_MANAGE_LOGS":
p.Permission = models.ApiPermManageLogs
case "PERM_MANAGE_FILE_REQUESTS":
p.Permission = models.ApiManageFileRequests
default:
return errors.New("invalid permission")
}
Expand Down Expand Up @@ -422,6 +424,8 @@ func (p *paramUserModify) ProcessParameter(_ *http.Request) error {
p.Permission = models.UserPermManageApiKeys
case "PERM_USERS":
p.Permission = models.UserPermManageUsers
case "PERM_GUEST_UPLOAD":
p.Permission = models.UserPermGuestUploads
default:
return errors.New("invalid permission")
}
Expand Down
36 changes: 36 additions & 0 deletions internal/webserver/authentication/users/Users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package users

import (
"errors"
"github.com/forceu/gokapi/internal/configuration"
"github.com/forceu/gokapi/internal/configuration/database"
"github.com/forceu/gokapi/internal/models"
)

const minLengthUser = 2

var ErrorNameToShort = errors.New("username too short")
var ErrorUserExists = errors.New("user already exists")

func Create(name string) (models.User, error) {
if len(name) < minLengthUser {
return models.User{}, ErrorNameToShort
}
_, ok := database.GetUserByName(name)
if ok {
return models.User{}, ErrorUserExists
}
newUser := models.User{
Name: name,
UserLevel: models.UserLevelUser,
}
if configuration.Get().AllowGuestUploadsByDefault {
newUser.GrantPermission(models.UserPermGuestUploads)
}
database.SaveUser(newUser, true)
newUser, ok = database.GetUserByName(name)
if !ok {
return models.User{}, errors.New("user could not be created")
}
return newUser, nil
}
Loading
Loading