Skip to content

Commit

Permalink
transitive commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pandadiestro committed Nov 23, 2024
1 parent 0ac3310 commit 23dce10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
42 changes: 7 additions & 35 deletions stiller-backend/internal/handlers/file/filedl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,23 @@ import (
"stiller/internal/dbutils"
"stiller/internal/fsutils"
"stiller/internal/handlers/handleutils"
"stiller/internal/jwtutils"
"strconv"

jsonexp "github.com/go-json-experiment/json"
"github.com/julienschmidt/httprouter"
"github.com/leporo/sqlf"
"zombiezen.com/go/sqlite"
"zombiezen.com/go/sqlite/sqlitex"
)


func Nethandler(
w http.ResponseWriter,
r *http.Request,
params httprouter.Params,
) {
func Nethandler(w http.ResponseWriter, r *http.Request, params httprouter.Params) {
if handleutils.CORS(w, r) {
return
}

type ReqPayload struct {
FileId int `json:"file_id"`
}

req_payload := ReqPayload{}
unmarshal_err := jsonexp.UnmarshalRead(
r.Body,
&req_payload,
jsonexp.DefaultOptionsV2(),
)

if handleutils.RequestLog(
unmarshal_err,
"",
http.StatusBadRequest,
&w,
) {
return
}

user_token := r.Header.Get("token")
user_tk, token_decode_err := jwtutils.Decode(user_token)
if handleutils.RequestLog(token_decode_err, "", http.StatusUnauthorized, &w) {
file_id_str := params.ByName("file_id")
file_id, file_id_err := strconv.Atoi(file_id_str)
if handleutils.RequestLog(file_id_err, "", http.StatusNotFound, &w) {
return
}

Expand All @@ -60,18 +35,15 @@ func Nethandler(
return
}

user_id := user_tk.UserId
getpath_stmt := sqlf.
Select("path").
From("file").
Where("owner = ?", user_id)
Where("id = ?", file_id)

getpath_query := getpath_stmt.String()
path := ""

exec_err := sqlitex.ExecuteTransient(
new_dbconn,
getpath_query,
getpath_stmt.String(),
&sqlitex.ExecOptions{
ResultFunc: func(stmt *sqlite.Stmt) error {
path = stmt.GetText("path")
Expand Down
2 changes: 1 addition & 1 deletion stiller-backend/internal/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var routes = [...]individualHandler{
handlefunc: upload.NetHandler,
},
{
path: "/file/dl",
path: "/file/dl/:file_id",
method: http.MethodGet,
handlefunc: filedl.Nethandler,
},
Expand Down

0 comments on commit 23dce10

Please sign in to comment.