mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-12 21:35:30 +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:
@@ -421,13 +421,11 @@ func doFile(rsp http.ResponseWriter, r *http.Request, repo *repomgr.Repo, fileID
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if operation != "view" {
|
oper := "web-file-download"
|
||||||
oper := "web-file-download"
|
if operation == "download-link" {
|
||||||
if operation == "download-link" {
|
oper = "link-file-download"
|
||||||
oper = "link-file-download"
|
|
||||||
}
|
|
||||||
sendStatisticMsg(repo.StoreID, user, oper, file.FileSize)
|
|
||||||
}
|
}
|
||||||
|
sendStatisticMsg(repo.StoreID, user, oper, file.FileSize)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -3799,7 +3797,11 @@ func accessLinkCB(rsp http.ResponseWriter, r *http.Request) *appError {
|
|||||||
repoID := info.RepoID
|
repoID := info.RepoID
|
||||||
filePath := normalizeUTF8Path(info.FilePath)
|
filePath := normalizeUTF8Path(info.FilePath)
|
||||||
fileName := filepath.Base(filePath)
|
fileName := filepath.Base(filePath)
|
||||||
op := "download-link"
|
|
||||||
|
op := r.URL.Query().Get("op")
|
||||||
|
if op != "view" {
|
||||||
|
op = "download-link"
|
||||||
|
}
|
||||||
|
|
||||||
ranges := r.Header["Range"]
|
ranges := r.Header["Range"]
|
||||||
byteRanges := strings.Join(ranges, "")
|
byteRanges := strings.Join(ranges, "")
|
||||||
|
@@ -338,14 +338,12 @@ next:
|
|||||||
|
|
||||||
evhtp_send_reply_end (data->req);
|
evhtp_send_reply_end (data->req);
|
||||||
|
|
||||||
if (g_strcmp0(data->token_type, "view") != 0) {
|
char *oper = "web-file-download";
|
||||||
char *oper = "web-file-download";
|
if (g_strcmp0(data->token_type, "download-link") == 0)
|
||||||
if (g_strcmp0(data->token_type, "download-link") == 0)
|
oper = "link-file-download";
|
||||||
oper = "link-file-download";
|
|
||||||
|
|
||||||
send_statistic_msg(data->store_id, data->user, oper,
|
send_statistic_msg(data->store_id, data->user, oper,
|
||||||
(guint64)data->file->file_size);
|
(guint64)data->file->file_size);
|
||||||
}
|
|
||||||
|
|
||||||
free_sendfile_data (data);
|
free_sendfile_data (data);
|
||||||
return;
|
return;
|
||||||
@@ -1811,6 +1809,7 @@ access_link_cb(evhtp_request_t *req, void *arg)
|
|||||||
const char *file_path = NULL;
|
const char *file_path = NULL;
|
||||||
const char *share_type = NULL;
|
const char *share_type = NULL;
|
||||||
const char *byte_ranges = NULL;
|
const char *byte_ranges = NULL;
|
||||||
|
const char *operation = NULL;
|
||||||
int error_code = EVHTP_RES_BADREQ;
|
int error_code = EVHTP_RES_BADREQ;
|
||||||
|
|
||||||
SeafileCryptKey *key = NULL;
|
SeafileCryptKey *key = NULL;
|
||||||
@@ -1833,6 +1832,11 @@ access_link_cb(evhtp_request_t *req, void *arg)
|
|||||||
|
|
||||||
token = parts[1];
|
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);
|
char *ip_addr = get_client_ip_addr (req);
|
||||||
const char *user_agent = evhtp_header_find (req->headers_in, "User-Agent");
|
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 (!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_str = "Internal server error\n";
|
||||||
error_code = EVHTP_RES_SERVERR;
|
error_code = EVHTP_RES_SERVERR;
|
||||||
goto out;
|
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_str = "Internal server error\n";
|
||||||
error_code = EVHTP_RES_SERVERR;
|
error_code = EVHTP_RES_SERVERR;
|
||||||
goto out;
|
goto out;
|
||||||
|
Reference in New Issue
Block a user