mirror of
https://github.com/mickael-kerjean/filestash
synced 2025-12-07 17:02:29 +01:00
fix (cloudflare): cloudflare chunked issue
This commit is contained in:
parent
f2e006b545
commit
1b47b613b6
2 changed files with 14 additions and 4 deletions
|
|
@ -335,13 +335,17 @@ function workerImplFile({ progress, speed }) {
|
||||||
async prepareJob({ file, path, virtual }) {
|
async prepareJob({ file, path, virtual }) {
|
||||||
const chunkSize = (window.CONFIG["upload_chunk_size"] || 0) *1024*1024;
|
const chunkSize = (window.CONFIG["upload_chunk_size"] || 0) *1024*1024;
|
||||||
const numberOfChunks = Math.ceil(file.size / chunkSize);
|
const numberOfChunks = Math.ceil(file.size / chunkSize);
|
||||||
|
const headersNoCache = {
|
||||||
|
"Cache-Control": "no-store",
|
||||||
|
"Pragma": "no-cache",
|
||||||
|
};
|
||||||
|
|
||||||
// Case1: basic upload
|
// Case1: basic upload
|
||||||
if (chunkSize === 0 || numberOfChunks === 0 || numberOfChunks === 1) {
|
if (chunkSize === 0 || numberOfChunks === 0 || numberOfChunks === 1) {
|
||||||
try {
|
try {
|
||||||
await executeHttp.call(this, toHref(`/api/files/cat?path=${encodeURIComponent(path)}`), {
|
await executeHttp.call(this, toHref(`/api/files/cat?path=${encodeURIComponent(path)}`), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {},
|
headers: { ...headersNoCache },
|
||||||
body: file,
|
body: file,
|
||||||
progress,
|
progress,
|
||||||
speed,
|
speed,
|
||||||
|
|
@ -359,7 +363,10 @@ function workerImplFile({ progress, speed }) {
|
||||||
try {
|
try {
|
||||||
let resp = await executeHttp.call(this, toHref(`/api/files/cat?path=${encodeURIComponent(path)}&proto=tus`), {
|
let resp = await executeHttp.call(this, toHref(`/api/files/cat?path=${encodeURIComponent(path)}&proto=tus`), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Upload-Length": file.size },
|
headers: {
|
||||||
|
"Upload-Length": file.size,
|
||||||
|
...headersNoCache,
|
||||||
|
},
|
||||||
body: null,
|
body: null,
|
||||||
progress: (n) => progress(n),
|
progress: (n) => progress(n),
|
||||||
speed,
|
speed,
|
||||||
|
|
@ -372,7 +379,10 @@ function workerImplFile({ progress, speed }) {
|
||||||
const offset = chunkSize * i;
|
const offset = chunkSize * i;
|
||||||
resp = await executeHttp.call(this, url, {
|
resp = await executeHttp.call(this, url, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: { "Upload-Offset": offset },
|
headers: {
|
||||||
|
"Upload-Offset": offset,
|
||||||
|
...headersNoCache,
|
||||||
|
},
|
||||||
body: file.slice(offset, offset + chunkSize),
|
body: file.slice(offset, offset + chunkSize),
|
||||||
progress: (p) => {
|
progress: (p) => {
|
||||||
const chunksAlreadyDownloaded = i * chunkSize;
|
const chunksAlreadyDownloaded = i * chunkSize;
|
||||||
|
|
|
||||||
|
|
@ -496,6 +496,7 @@ func FileSave(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if proto == "tus" && req.Method == http.MethodPatch {
|
if proto == "tus" && req.Method == http.MethodPatch {
|
||||||
|
h.Set("Connection", "Close")
|
||||||
requestOffset, err := strconv.ParseUint(req.Header.Get("Upload-Offset"), 10, 0)
|
requestOffset, err := strconv.ParseUint(req.Header.Get("Upload-Offset"), 10, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendErrorResult(res, ErrNotValid)
|
SendErrorResult(res, ErrNotValid)
|
||||||
|
|
@ -530,7 +531,6 @@ func FileSave(ctx *App, res http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
chunkedUploadCache.Del(ctx.Session)
|
chunkedUploadCache.Del(ctx.Session)
|
||||||
}
|
}
|
||||||
h.Set("Connection", "Close")
|
|
||||||
h.Set("Upload-Offset", fmt.Sprintf("%d", newOffset))
|
h.Set("Upload-Offset", fmt.Sprintf("%d", newOffset))
|
||||||
res.WriteHeader(http.StatusNoContent)
|
res.WriteHeader(http.StatusNoContent)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue