1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-04-27 19:15:07 +00:00

Add op to download or view file (#722)

* Add op to download or view file

* Use download-link op and statistic view

* Go add statictic view

---------

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
feiniks 2024-12-05 15:08:25 +08:00 committed by GitHub
parent 04e190ce7e
commit e8c0e81b57
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 16 deletions

View File

@ -421,13 +421,11 @@ func doFile(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, fileID
}
}
if operation != "view" {
oper := "web-file-download"
if operation == "download-link" {
oper = "link-file-download"
}
sendStatisticMsg(repo.StoreID, user, oper, file.FileSize)
oper := "web-file-download"
if operation == "download-link" {
oper = "link-file-download"
}
sendStatisticMsg(repo.StoreID, user, oper, file.FileSize)
return nil
}
@ -3799,7 +3797,11 @@ func accessLinkCB(rsp http.ResponseWriter, r *http.Request) *appError {
repoID := info.RepoID
filePath := normalizeUTF8Path(info.FilePath)
fileName := filepath.Base(filePath)
op := "download-link"
op := r.URL.Query().Get("op")
if op != "view" {
op = "download-link"
}
ranges := r.Header["Range"]
byteRanges := strings.Join(ranges, "")

View File

@ -338,14 +338,12 @@ next:
evhtp_send_reply_end (data->req);
if (g_strcmp0(data->token_type, "view") != 0) {
char *oper = "web-file-download";
if (g_strcmp0(data->token_type, "download-link") == 0)
oper = "link-file-download";
char *oper = "web-file-download";
if (g_strcmp0(data->token_type, "download-link") == 0)
oper = "link-file-download";
send_statistic_msg(data->store_id, data->user, oper,
(guint64)data->file->file_size);
}
send_statistic_msg(data->store_id, data->user, oper,
(guint64)data->file->file_size);
free_sendfile_data (data);
return;
@ -1811,6 +1809,7 @@ access_link_cb(evhtp_request_t *req, void *arg)
const char *file_path = NULL;
const char *share_type = NULL;
const char *byte_ranges = NULL;
const char *operation = NULL;
int error_code = EVHTP_RES_BADREQ;
SeafileCryptKey *key = NULL;
@ -1833,6 +1832,11 @@ access_link_cb(evhtp_request_t *req, void *arg)
token = parts[1];
operation = evhtp_kv_find (req->uri->query, "op");
if (g_strcmp0 (operation, "view") != 0) {
operation = "download-link";
}
char *ip_addr = get_client_ip_addr (req);
const char *user_agent = evhtp_header_find (req->headers_in, "User-Agent");
@ -1917,12 +1921,12 @@ access_link_cb(evhtp_request_t *req, void *arg)
}
if (!repo->encrypted && byte_ranges) {
if (do_file_range (req, repo, file_id, filename, "download-link", byte_ranges, user) < 0) {
if (do_file_range (req, repo, file_id, filename, operation, byte_ranges, user) < 0) {
error_str = "Internal server error\n";
error_code = EVHTP_RES_SERVERR;
goto out;
}
} else if (do_file(req, repo, file_id, filename, "download-link", key, user) < 0) {
} else if (do_file(req, repo, file_id, filename, operation, key, user) < 0) {
error_str = "Internal server error\n";
error_code = EVHTP_RES_SERVERR;
goto out;