diff --git a/server/web/api/upload.go b/server/web/api/upload.go index cd1d1eab0..983a0cc52 100644 --- a/server/web/api/upload.go +++ b/server/web/api/upload.go @@ -1,11 +1,13 @@ package api import ( + "mime/multipart" "net/http" "server/log" set "server/settings" "server/torr" + "server/torr/state" "server/web/api/utils" "github.com/gin-gonic/gin" @@ -13,22 +15,22 @@ import ( // torrentUpload godoc // -// @Summary Add .torrent file -// @Description Only one file support. +// @Summary Add .torrent files +// @Description Supports multiple files. Returns array of statuses. // // @Tags API // -// @Param file formData file true "Torrent file to insert" +// @Param file formData file true "Torrent file(s) to insert" // @Param save formData string false "Save to DB" -// @Param title formData string false "Torrent title" +// @Param title formData string false "Torrent title (single file only)" // @Param category formData string false "Torrent category" -// @Param poster formData string false "Torrent poster" +// @Param poster formData string false "Torrent poster (single file only)" // @Param data formData string false "Torrent data" // // @Accept multipart/form-data // // @Produce json -// @Success 200 {object} state.TorrentStatus "Torrent status" +// @Success 200 {array} state.TorrentStatus "Torrent statuses" // @Router /torrent/upload [post] func torrentUpload(c *gin.Context) { form, err := c.MultipartForm() @@ -55,24 +57,34 @@ func torrentUpload(c *gin.Context) { if len(form.Value["data"]) > 0 { data = form.Value["data"][0] } - var tor *torr.Torrent - for name, file := range form.File { - log.TLogln("add .torrent", name) - torrFile, err := file[0].Open() + var files []*multipart.FileHeader + for _, fh := range form.File { + files = append(files, fh...) + } + + var stats []*state.TorrentStatus + for _, fh := range files { + log.TLogln("add .torrent", fh.Filename) + + torrFile, err := fh.Open() if err != nil { log.TLogln("error upload torrent:", err) continue } - defer torrFile.Close() spec, err := utils.ParseFile(torrFile) + torrFile.Close() if err != nil { log.TLogln("error upload torrent:", err) continue } - tor, err = torr.AddTorrent(spec, title, poster, data, category) + tor, err := torr.AddTorrent(spec, title, poster, data, category) + if err != nil { + log.TLogln("error upload torrent:", err) + continue + } if tor.Data != "" && set.BTsets.EnableDebug { log.TLogln("torrent data:", tor.Data) @@ -81,27 +93,22 @@ func torrentUpload(c *gin.Context) { log.TLogln("torrent category:", tor.Category) } - if err != nil { - log.TLogln("error upload torrent:", err) - continue - } - - go func() { - if !tor.GotInfo() { + go func(t *torr.Torrent) { + if !t.GotInfo() { log.TLogln("error add torrent:", "torrent connection timeout") return } - if tor.Title == "" { - tor.Title = tor.Name() + if t.Title == "" { + t.Title = t.Name() } if save { - torr.SaveTorrentToDB(tor) + torr.SaveTorrentToDB(t) } - }() + }(tor) - break + stats = append(stats, tor.Status()) } - c.JSON(200, tor.Status()) + c.JSON(200, stats) } diff --git a/server/web/pages/template/html.go b/server/web/pages/template/html.go index 85c5dd18f..1afee6255 100644 --- a/server/web/pages/template/html.go +++ b/server/web/pages/template/html.go @@ -118,20 +118,20 @@ var Mstile150x150png []byte //go:embed pages/site.webmanifest var Sitewebmanifest []byte -//go:embed pages/static/js/2.d0681903.chunk.js -var Staticjs2d0681903chunkjs []byte +//go:embed pages/static/js/2.c7959c35.chunk.js +var Staticjs2c7959c35chunkjs []byte -//go:embed pages/static/js/2.d0681903.chunk.js.LICENSE.txt -var Staticjs2d0681903chunkjsLICENSEtxt []byte +//go:embed pages/static/js/2.c7959c35.chunk.js.LICENSE.txt +var Staticjs2c7959c35chunkjsLICENSEtxt []byte -//go:embed pages/static/js/2.d0681903.chunk.js.map -var Staticjs2d0681903chunkjsmap []byte +//go:embed pages/static/js/2.c7959c35.chunk.js.map +var Staticjs2c7959c35chunkjsmap []byte -//go:embed pages/static/js/main.53e2dc27.chunk.js -var Staticjsmain53e2dc27chunkjs []byte +//go:embed pages/static/js/main.c937891b.chunk.js +var Staticjsmainc937891bchunkjs []byte -//go:embed pages/static/js/main.53e2dc27.chunk.js.map -var Staticjsmain53e2dc27chunkjsmap []byte +//go:embed pages/static/js/main.c937891b.chunk.js.map +var Staticjsmainc937891bchunkjsmap []byte //go:embed pages/static/js/runtime-main.5ed86a79.js var Staticjsruntimemain5ed86a79js []byte diff --git a/server/web/pages/template/pages/asset-manifest.json b/server/web/pages/template/pages/asset-manifest.json index 44ded661a..f52fe29b6 100644 --- a/server/web/pages/template/pages/asset-manifest.json +++ b/server/web/pages/template/pages/asset-manifest.json @@ -1,17 +1,17 @@ { "files": { - "main.js": "./static/js/main.53e2dc27.chunk.js", - "main.js.map": "./static/js/main.53e2dc27.chunk.js.map", + "main.js": "./static/js/main.c937891b.chunk.js", + "main.js.map": "./static/js/main.c937891b.chunk.js.map", "runtime-main.js": "./static/js/runtime-main.5ed86a79.js", "runtime-main.js.map": "./static/js/runtime-main.5ed86a79.js.map", - "static/js/2.d0681903.chunk.js": "./static/js/2.d0681903.chunk.js", - "static/js/2.d0681903.chunk.js.map": "./static/js/2.d0681903.chunk.js.map", + "static/js/2.c7959c35.chunk.js": "./static/js/2.c7959c35.chunk.js", + "static/js/2.c7959c35.chunk.js.map": "./static/js/2.c7959c35.chunk.js.map", "index.html": "./index.html", - "static/js/2.d0681903.chunk.js.LICENSE.txt": "./static/js/2.d0681903.chunk.js.LICENSE.txt" + "static/js/2.c7959c35.chunk.js.LICENSE.txt": "./static/js/2.c7959c35.chunk.js.LICENSE.txt" }, "entrypoints": [ "static/js/runtime-main.5ed86a79.js", - "static/js/2.d0681903.chunk.js", - "static/js/main.53e2dc27.chunk.js" + "static/js/2.c7959c35.chunk.js", + "static/js/main.c937891b.chunk.js" ] } \ No newline at end of file diff --git a/server/web/pages/template/pages/index.html b/server/web/pages/template/pages/index.html index 25e7563a0..101b0e515 100644 --- a/server/web/pages/template/pages/index.html +++ b/server/web/pages/template/pages/index.html @@ -1 +1 @@ -
0)&&n.host.split("@"))&&(n.auth=R.shift(),n.hostname=R.shift(),n.host=n.hostname);return n.search=e.search,n.query=e.query,null===n.pathname&&null===n.search||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!O.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var E=O.slice(-1)[0],k=(n.host||e.host||O.length>1)&&("."===E||".."===E)||""===E,j=0,C=O.length;C>=0;C--)"."===(E=O[C])?O.splice(C,1):".."===E?(O.splice(C,1),j++):j&&(O.splice(C,1),j--);if(!w&&!x)for(;j--;j)O.unshift("..");!w||""===O[0]||O[0]&&"/"===O[0].charAt(0)||O.unshift(""),k&&"/"!==O.join("/").substr(-1)&&O.push("");var R,_=""===O[0]||O[0]&&"/"===O[0].charAt(0);S&&(n.hostname=_?"":O.length?O.shift():"",n.host=n.hostname,(R=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=R.shift(),n.hostname=R.shift(),n.host=n.hostname));return(w=w||n.host&&O.length)&&!_&&O.unshift(""),O.length>0?n.pathname=O.join("/"):(n.pathname=null,n.path=null),null===n.pathname&&null===n.search||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},o.prototype.parseHost=function(){var e=this.host,t=a.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)},t.parse=g,t.resolve=function(e,t){return g(e,!1,!0).resolve(t)},t.resolveObject=function(e,t){return e?g(e,!1,!0).resolveObject(t):t},t.format=function(e){return"string"===typeof e&&(e=g(e)),e instanceof o?e.format():o.prototype.format.call(e)},t.Url=o},function(e,t,n){"use strict";var r,o=n(184),i=n(390),a=n(391),s=n(392),u=n(393),l=n(394),c=n(83),f=n(395),d=n(396),p=n(397),h=n(398),m=n(399),v=n(400),y=n(401),g=n(402),b=Function,w=function(e){try{return b('"use strict"; return ('+e+").constructor;")()}catch(t){}},x=n(185),O=n(405),S=function(){throw new c},E=x?function(){try{return S}catch(e){try{return x(arguments,"callee").get}catch(t){return S}}}():S,k=n(406)(),j=n(408),C=n(187),R=n(186),_=n(189),P=n(139),T={},A="undefined"!==typeof Uint8Array&&j?j(Uint8Array):r,L={__proto__:null,"%AggregateError%":"undefined"===typeof AggregateError?r:AggregateError,"%Array%":Array,"%ArrayBuffer%":"undefined"===typeof ArrayBuffer?r:ArrayBuffer,"%ArrayIteratorPrototype%":k&&j?j([][Symbol.iterator]()):r,"%AsyncFromSyncIteratorPrototype%":r,"%AsyncFunction%":T,"%AsyncGenerator%":T,"%AsyncGeneratorFunction%":T,"%AsyncIteratorPrototype%":T,"%Atomics%":"undefined"===typeof Atomics?r:Atomics,"%BigInt%":"undefined"===typeof BigInt?r:BigInt,"%BigInt64Array%":"undefined"===typeof BigInt64Array?r:BigInt64Array,"%BigUint64Array%":"undefined"===typeof BigUint64Array?r:BigUint64Array,"%Boolean%":Boolean,"%DataView%":"undefined"===typeof DataView?r:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":i,"%eval%":eval,"%EvalError%":a,"%Float32Array%":"undefined"===typeof Float32Array?r:Float32Array,"%Float64Array%":"undefined"===typeof Float64Array?r:Float64Array,"%FinalizationRegistry%":"undefined"===typeof FinalizationRegistry?r:FinalizationRegistry,"%Function%":b,"%GeneratorFunction%":T,"%Int8Array%":"undefined"===typeof Int8Array?r:Int8Array,"%Int16Array%":"undefined"===typeof Int16Array?r:Int16Array,"%Int32Array%":"undefined"===typeof Int32Array?r:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":k&&j?j(j([][Symbol.iterator]())):r,"%JSON%":"object"===typeof JSON?JSON:r,"%Map%":"undefined"===typeof Map?r:Map,"%MapIteratorPrototype%":"undefined"!==typeof Map&&k&&j?j((new Map)[Symbol.iterator]()):r,"%Math%":Math,"%Number%":Number,"%Object%":o,"%Object.getOwnPropertyDescriptor%":x,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":"undefined"===typeof Promise?r:Promise,"%Proxy%":"undefined"===typeof Proxy?r:Proxy,"%RangeError%":s,"%ReferenceError%":u,"%Reflect%":"undefined"===typeof Reflect?r:Reflect,"%RegExp%":RegExp,"%Set%":"undefined"===typeof Set?r:Set,"%SetIteratorPrototype%":"undefined"!==typeof Set&&k&&j?j((new Set)[Symbol.iterator]()):r,"%SharedArrayBuffer%":"undefined"===typeof SharedArrayBuffer?r:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":k&&j?j(""[Symbol.iterator]()):r,"%Symbol%":k?Symbol:r,"%SyntaxError%":l,"%ThrowTypeError%":E,"%TypedArray%":A,"%TypeError%":c,"%Uint8Array%":"undefined"===typeof Uint8Array?r:Uint8Array,"%Uint8ClampedArray%":"undefined"===typeof Uint8ClampedArray?r:Uint8ClampedArray,"%Uint16Array%":"undefined"===typeof Uint16Array?r:Uint16Array,"%Uint32Array%":"undefined"===typeof Uint32Array?r:Uint32Array,"%URIError%":f,"%WeakMap%":"undefined"===typeof WeakMap?r:WeakMap,"%WeakRef%":"undefined"===typeof WeakRef?r:WeakRef,"%WeakSet%":"undefined"===typeof WeakSet?r:WeakSet,"%Function.prototype.call%":P,"%Function.prototype.apply%":_,"%Object.defineProperty%":O,"%Object.getPrototypeOf%":C,"%Math.abs%":d,"%Math.floor%":p,"%Math.max%":h,"%Math.min%":m,"%Math.pow%":v,"%Math.round%":y,"%Math.sign%":g,"%Reflect.getPrototypeOf%":R};if(j)try{null.error}catch(K){var M=j(j(K));L["%Error.prototype%"]=M}var N=function e(t){var n;if("%AsyncFunction%"===t)n=w("async function () {}");else if("%GeneratorFunction%"===t)n=w("function* () {}");else if("%AsyncGeneratorFunction%"===t)n=w("async function* () {}");else if("%AsyncGenerator%"===t){var r=e("%AsyncGeneratorFunction%");r&&(n=r.prototype)}else if("%AsyncIteratorPrototype%"===t){var o=e("%AsyncGenerator%");o&&j&&(n=j(o.prototype))}return L[t]=n,n},I={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},D=n(108),F=n(413),z=D.call(P,Array.prototype.concat),B=D.call(_,Array.prototype.splice),U=D.call(P,String.prototype.replace),H=D.call(P,String.prototype.slice),W=D.call(P,RegExp.prototype.exec),V=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,q=/\\(\\)?/g,$=function(e,t){var n,r=e;if(F(I,r)&&(r="%"+(n=I[r])[0]+"%"),F(L,r)){var o=L[r];if(o===T&&(o=N(r)),"undefined"===typeof o&&!t)throw new c("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:n,name:r,value:o}}throw new l("intrinsic "+e+" does not exist!")};e.exports=function(e,t){if("string"!==typeof e||0===e.length)throw new c("intrinsic name must be a non-empty string");if(arguments.length>1&&"boolean"!==typeof t)throw new c('"allowMissing" argument must be a boolean');if(null===W(/^%?[^%]*%?$/,e))throw new l("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var n=function(e){var t=H(e,0,1),n=H(e,-1);if("%"===t&&"%"!==n)throw new l("invalid intrinsic syntax, expected closing `%`");if("%"===n&&"%"!==t)throw new l("invalid intrinsic syntax, expected opening `%`");var r=[];return U(e,V,(function(e,t,n,o){r[r.length]=n?U(o,q,"$1"):t||e})),r}(e),r=n.length>0?n[0]:"",o=$("%"+r+"%",t),i=o.name,a=o.value,s=!1,u=o.alias;u&&(r=u[0],B(n,z([0,1],u)));for(var f=1,d=!0;fr.charCodeAt(0)&&(r=r.trim()),r=[r],0s[h]&&(e.offsets.popper[d]+=u[d]+m-s[h]),e.offsets.popper=S(e.offsets.popper);var v=u[d]+u[c]/2-m/2,y=a(e.instance.popper),g=parseFloat(y["margin"+f]),b=parseFloat(y["border"+f+"Width"]),w=v-e.offsets.popper[d]-g-b;return w=Math.max(Math.min(s[c]-m,w),0),e.arrowElement=r,e.offsets.arrow=(x(n={},d,Math.round(w)),x(n,p,""),n),e},element:"[x-arrow]"},flip:{order:600,enabled:!0,fn:function(e,t){if(D(e.instance.modifiers,"inner"))return e;if(e.flipped&&e.placement===e.originalPlacement)return e;var n=R(e.instance.popper,e.instance.reference,t.padding,t.boundariesElement,e.positionFixed),r=e.placement.split("-")[0],o=A(r),i=e.placement.split("-")[1]||"",a=[];switch(t.behavior){case J:a=[r,o];break;case Z:a=X(r);break;case ee:a=X(r,!0);break;default:a=t.behavior}return a.forEach((function(s,u){if(r!==s||a.length===u+1)return e;r=e.placement.split("-")[0],o=A(r);var l=e.offsets.popper,c=e.offsets.reference,f=Math.floor,d="left"===r&&f(l.right)>f(c.left)||"right"===r&&f(l.left)>1,c=-7,f=n?o-1:0,d=n?-1:1,p=e[t+f];for(f+=d,i=p&(1<<-c)-1,p>>=-c,c+=s;c>0;i=256*i+e[t+f],f+=d,c-=8);for(a=i&(1<<-c)-1,i>>=-c,c+=r;c>0;a=256*a+e[t+f],f+=d,c-=8);if(0===i)i=1-l;else{if(i===u)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,r),i-=l}return(p?-1:1)*a*Math.pow(2,i-r)},t.write=function(e,t,n,r,o,i){var a,s,u,l=8*i-o-1,c=(1<=i?a(u,e):(n=u,r||(r=setTimeout((()=>{r=null,a(n)}),i-t)))},()=>n&&a(n)]};const H=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:3,r=0;const o=B(50,250);return U((n=>{const i=n.loaded,a=n.lengthComputable?n.total:void 0,s=i-r,u=o(s);r=i;e({loaded:i,total:a,progress:a?i/a:void 0,bytes:s,rate:u||void 0,estimated:u&&a&&i<=a?(a-i)/u:void 0,event:n,lengthComputable:null!=a,[t?"download":"upload"]:!0})}),n)},W=(e,t)=>{const n=null!=e;return[r=>t[0]({lengthComputable:n,total:e,loaded:r}),t[1]]},V=e=>function(){for(var t=arguments.length,n=new Array(t),r=0;r