mirror of
https://github.com/glimpse-app/server.git
synced 2025-04-02 10:52:45 -04:00
File counter fixes #12
This commit is contained in:
parent
01d93992b4
commit
22d338d5bb
7 changed files with 50 additions and 2 deletions
8
Dockerfile
Normal file
8
Dockerfile
Normal file
|
@ -0,0 +1,8 @@
|
|||
FROM --platform=$BUILDPLATFORM debian:latest AS builder
|
||||
RUN apt update -y
|
||||
RUN apt-get install sqlite3 -y
|
||||
WORKDIR /app/
|
||||
COPY . .
|
||||
RUN chmod +x server
|
||||
ENTRYPOINT ["./server"]
|
||||
EXPOSE 5000
|
|
@ -66,6 +66,8 @@ proc createDeletionRoutes*() =
|
|||
resp Http404, "File does not exist.\n"
|
||||
|
||||
db.delete(file)
|
||||
dec user.fileCount
|
||||
db.update(user)
|
||||
resp Http200, "File has been deleted.\n"
|
||||
|
||||
#[
|
||||
|
@ -88,7 +90,8 @@ proc createDeletionRoutes*() =
|
|||
for i in 0..(listOfFiles.len - 1):
|
||||
var file = listOfFiles[i]
|
||||
db.delete(file)
|
||||
|
||||
user.fileCount = 0
|
||||
db.update(user)
|
||||
removeDir("uploads/" & user.username & "/")
|
||||
|
||||
resp Http200, "All files have been deleted.\n"
|
||||
|
|
|
@ -31,7 +31,7 @@ proc createDownloadRoutes*() =
|
|||
returns:
|
||||
JSON - JSON node containing all files and tags
|
||||
]#
|
||||
get "/api/v1/listAllFiles":
|
||||
get "/api/v1/listOfAllFiles":
|
||||
var user = newUser()
|
||||
if not db.validToken(user, H"Authorization"):
|
||||
resp Http403, "Invalid token.\n"
|
||||
|
|
|
@ -46,6 +46,7 @@ proc createUploadRoutes*() =
|
|||
# create new file object and add to db
|
||||
var file = newFile(user, filePath, fileName, fileTags)
|
||||
db.insert(file)
|
||||
db.update(user)
|
||||
|
||||
# write the file from memory
|
||||
writeFile(filePath, fileData)
|
||||
|
|
|
@ -11,4 +11,5 @@ type File* = ref object of Model
|
|||
# creates a new file object and sets default values, recommended by the norm documentation
|
||||
func newFile*(user: User = newUser(), path: string = "", name: string = "",
|
||||
tags: string = ""): File =
|
||||
inc user.fileCount
|
||||
File(owner: user, path: path, name: name, tags: tags)
|
||||
|
|
|
@ -8,6 +8,7 @@ type User* = ref object of Model
|
|||
email*: string # should be unique
|
||||
password*: string # sha3-512 hash
|
||||
token*: string # should be unique
|
||||
fileCount*: int = 0
|
||||
|
||||
# checks if the provided token exists in the database
|
||||
proc validToken*(db: DbConn, user: var User, token: string): bool =
|
||||
|
|
34
test.Dockerfile
Normal file
34
test.Dockerfile
Normal file
|
@ -0,0 +1,34 @@
|
|||
#FROM --platform=$BUILDPLATFORM nimlang/nim AS builder
|
||||
FROM --platform=$BUILDPLATFORM nimlang/nim:alpine AS builder
|
||||
#FROM nimlang/nim:2.0.0-alpine-regular AS builder
|
||||
|
||||
RUN apk --no-cache update && apk --no-cache upgrade
|
||||
|
||||
WORKDIR /src/
|
||||
COPY . .
|
||||
|
||||
RUN nimble install -y jester norm checksums
|
||||
RUN nimble build --verbose --spellSuggest --deepcopy:on -d:nimDebugDlOpen -d:normDebug
|
||||
|
||||
|
||||
#FROM --platform=$BUILDPLATFORM debian:latest AS runner
|
||||
FROM --platform=$BUILDPLATFORM nimlang/nim:alpine AS runner
|
||||
#FROM --platform=$BUILDPLATFORM archlinux:base AS runner
|
||||
# https://github.com/nim-lang/Nim/issues/22546
|
||||
|
||||
WORKDIR /app/
|
||||
|
||||
#RUN apt update -y && apt upgrade -y && apt autoremove -y
|
||||
#RUN apt install sqlite3 -y
|
||||
RUN apk --no-cache update && apk --no-cache upgrade
|
||||
RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
|
||||
RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.35-r1/glibc-2.35-r1.apk
|
||||
RUN apk add glibc-2.35-r1.apk
|
||||
RUN apk add --no-cache --virtual=.build-deps pcre ca-certificates sqlite sqlite-libs sqlite-dev build-base
|
||||
|
||||
#RUN pacman -Syyuu --noconfirm
|
||||
|
||||
COPY --from=builder /src/server /app/
|
||||
|
||||
ENTRYPOINT ["/app/server"]
|
||||
EXPOSE 5000
|
Loading…
Add table
Reference in a new issue