This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
forked from csznet/tgState
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
443 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{{template "public/header" .}} | ||
<h1>上传文件到 Telegram</h1><label for=uploadFile id=uploadFileLabel class=custom-file-label>选择文件或拖拽到此区域</label> <input type=file name=image id=uploadFile class=custom-file-input multiple> <button id=uploadButton>上传</button><div id=loading>上传中...</div><div id=response class=ui-widget></div> | ||
{{template "public/footer" .}} | ||
<h1>上传文件到 Telegram</h1><label for=uploadFile id=uploadFileLabel class=custom-file-label>选择文件或拖拽到此区域</label><input type=file name=image id=uploadFile class=custom-file-input multiple><button id=uploadButton>点击上传</button><div id=response class=ui-widget></div> | ||
{{template "public/footer" .}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{{define "public/footer"}} | ||
<script defer>const $uploadButton=document.getElementById("uploadButton"),$response=document.getElementById("response"),$loading=document.getElementById("loading"),$uploadFile=document.getElementById("uploadFile"),$uploadFileLabel=document.getElementById("uploadFileLabel"),$copyCodeButtons_text=".copy-code";function uploadFile(e){const t=20971520,n=e.name,o=e=>console.log(e),l=e=>{console.error(e);const t=`上传失败(${e.message})`;return $response.prepend(createResponseElement(t,"response-error")),Promise.reject("Upload failed")};if(e.size<=t)uploadImg(e,1).then(o).catch(l);else{let o,a=`tgstate-blob\n${n}`;const d=(l,s,r=0)=>{if(l<e.size){return uploadImg(e.slice(l,s),0,o).then((n=>(a+=`\n${n.substring(14)}`,l=s,s=Math.min(l+t,e.size),d(l,s))),(e=>{if(r<5)return o=`${n}上传块失败,2秒后重试 (${r+1}/5)`,console.warn(o),new Promise((e=>setTimeout(e,2e3))).then((()=>d(l,s,r+1)));throw console.error(`${n}上传块失败,已达到最大重试次数 (5)`),e}))}return Promise.resolve()};d(0,t).then((()=>{console.log(a);const e=new Blob([a],{type:"text/plain"});return uploadImg(new File([e],`${n}_fileAll.txt`,{type:"text/plain"}),1)})).catch(l)}}function uploadImg(e,t,n){const o=e.name;return new Promise(((l,a)=>{const d=new FormData;d.append("file",e);const s=e.type.startsWith("image/");$uploadButton.disabled=!0,$uploadButton.textContent=`${o}上传中`,$loading.style.display="block";const r=window.location.origin;fetch(`${r}/api`,{method:"POST",body:d,headers:{}}).then((e=>e.json())).then((e=>{const d=`${r}${e.message}?filename=${o}`,i=document.createElement("div");return 1===e.code?(t&&(s?(i.className="response-item response-success",i.innerHTML=`${o}上传成功,图片外链:<a target="_blank" href="${d}">${d}</a><div class="copy-links">\n <span class="copy-code" data-clipboard-text="<img src="${d}" alt="Your Alt Text">">HTML</span>\n <span class="copy-code" data-clipboard-text="">Markdown</span>\n <span class="copy-code" data-clipboard-text="[img]${d}[/img]">BBCode</span>\n </div>`):(i.className="response-item response-success",i.innerHTML=`${o}上传成功,文件外链:<a target="_blank" href="${d}">${d}</a>`)),l(e.message)):(i.className="response-item response-error",i.textContent=n||`${o}上传失败(${e.message})`,a(`${o}上传失败(${e.message})`)),i.className&&$response.prepend(i),$uploadFile.value="",$uploadFileLabel.textContent="选择文件或拖拽到此区域",$uploadFileLabel.style.backgroundColor="#007BFF",document.querySelectorAll($copyCodeButtons_text).forEach((function(e){e.addEventListener("click",(function(){let e=this.dataset.clipboardText,t=document.createElement("input");document.body.appendChild(t),t.value=e,t.select(),document.execCommand("copy"),document.body.removeChild(t);let n=this,o=n.textContent;n.textContent="复制成功",setTimeout((function(){n.textContent=o}),500)}))})),e.message})).catch((e=>{let t=document.createElement("div");t.className="response-item response-error",t.textContent=`${o}上传失败`,$response.appendChild(t),a(`${o}上传失败`)})).finally((()=>{$uploadButton.disabled=!1,$uploadButton.textContent="上传",$loading.style.display="none"}))}))}function readAndUploadFile(e){const t=new FileReader;t.onload=function(t){const n=t.target.result;uploadFile(e,n)},t.readAsText(e)}function handleFileSelection(e){e.length>0?1===e.length?($uploadFileLabel.textContent="已选择文件: "+e[0].name,$uploadFileLabel.style.backgroundColor="#0056b3"):($uploadFileLabel.textContent="已选择多个文件",$uploadFileLabel.style.backgroundColor="#0056b3"):($uploadFileLabel.textContent="选择文件或拖拽到此区域",$uploadFileLabel.style.backgroundColor="#007BFF")}document.addEventListener("DOMContentLoaded",(function(){$uploadFile.addEventListener("change",(function(){handleFileSelection(this.files)})),$uploadButton.addEventListener("click",(function(){if($uploadFile.files.length>0)for(let e=0;e<$uploadFile.files.length;e++)readAndUploadFile($uploadFile.files[e]);else alert("请至少选择一个文件")}));let e=0;document.documentElement.addEventListener("dragover",(function(e){e.preventDefault()})),document.documentElement.addEventListener("dragenter",(function(t){t.preventDefault(),0===e&&(document.documentElement.style.backgroundColor="rgba(0, 123, 255, 0.1)"),e++})),document.documentElement.addEventListener("dragleave",(function(t){e--,0===e&&(document.documentElement.style.backgroundColor="transparent")})),document.documentElement.addEventListener("drop",(function(t){t.preventDefault(),document.documentElement.style.backgroundColor="transparent",$uploadFile.files=t.dataTransfer.files,handleFileSelection(t.dataTransfer.files),e=0}))}))</script> | ||
<script defer>const $uploadButton=document.getElementById("uploadButton"),$response=document.getElementById("response"),$uploadFile=document.getElementById("uploadFile"),$uploadFileLabel=document.getElementById("uploadFileLabel"),$copyCodeButtons_text=".copy-code",errorClassName="response-item response-error",successClassName="response-item response-success",serverUrl=window.location.origin,serverUrl_API=`${serverUrl}/api`,SizeThreshold=20971520,retryCount=5,retryDelay=2e3,sleep=e=>new Promise((t=>setTimeout(t,e))),uploadFile=e=>{const t=e.name,o=e=>console.log(`${t}: ${serverUrl}${e}`),n=e=>($uploadButton.disabled=!1,$uploadButton.textContent="点击上传",console.error("上传失败! ",e),Promise.reject("上传失败! ",e));if(e.size<=20971520)handleFileUpload(e,1,t).then(o).catch(n);else{let l=`tgstate-blob\n${t}`,a=`${t}上传块第一次失败,将以每2秒重试(5)次!`;const s=(o,n,r=0)=>{if(o<e.size){const d=e.slice(o,n);return handleFileUpload(d,0,t,a).then((t=>(l+=`\n${t.substring(14)}`,o=n,n=Math.min(o+20971520,e.size),s(o,n))),(l=>r<5?(a=`${t}上传块失败,2秒后重试 (${r+1}/5)`,console.warn(a),creatErrorElement(e,t,a,l),sleep(2e3).then((()=>s(o,n,r+1)))):(a=`${t}上传失败!已达到最大重试次数(5)!`,console.error(a),creatErrorElement(e,t,a,l),Promise.reject(a))))}return Promise.resolve()};s(0,20971520).then((()=>{console.log(l);const e=new Blob([l],{type:"text/plain"}),o=new File([e],`${t}_fileAll.txt`,{type:"text/plain"});return handleFileUpload(o,1,t)})).then(o).catch(n)}},creatErrorElement=(e,t,o,n)=>{const l=`${t}_${e.size}_${e.lastModified}`,a=$response.querySelector(`.response-item.response-error[data-identifier="${l}"]`),s=o?`${o} (${n})`:`${t}上传失败! (${n})`;if(a)a.textContent=s;else{const e=document.createElement("div");e.className=errorClassName,e.textContent=s,$response.prepend(e)}},handleFileUpload=(e,t,o,n)=>new Promise(((l,a)=>{const s=new FormData;s.append("file",e),$uploadButton.disabled||($uploadButton.disabled=!0,$uploadButton.textContent=`${o}上传中`),fetch(serverUrl_API,{method:"POST",body:s,headers:{}}).then((e=>e.json())).then((n=>{if(1===n.code){if(l(n.message),t){const t=`${serverUrl}${n.message}?filename=${o}`,l=document.createElement("div"),a=e.type.startsWith("image/")?"图片":"文件";l.className=successClassName,l.innerHTML=`<p>${o}上传成功,${a}外链: </p><a target="_blank" href="${t}">${t}</a><div class="copy-links"><span class="copy-code" data-clipboard-text="<img src="${t}" alt="Your Alt Text">">HTML</span><span class="copy-code" data-clipboard-text="">Markdown</span><span class="copy-code" data-clipboard-text="[img]${t}[/img]">BBCode</span><span class="copy-code" data-clipboard-text="${t}">复制外链</span></div>`,$response.prepend(l),$uploadFile.value="",$uploadFileLabel.textContent="选择文件或拖拽到此区域",$uploadFileLabel.style.backgroundColor="#007BFF",$uploadButton.disabled=!1,$uploadButton.textContent="点击上传"}}else a(n.message)})).catch((()=>{creatErrorElement(e,o,n,response.message)}))})),$copyCodeButtonsContainer=document.body;$copyCodeButtonsContainer.addEventListener("click",(function(e){const t=e.target.closest(".copy-code");if(t){const e=t.dataset.clipboardText,o=t.textContent;try{navigator.clipboard.writeText(e)}catch(e){console.error("使用Clipboard API复制失败:",e);const o=t.dataset.clipboardText,n=document.createElement("input");document.body.appendChild(n),n.value=o,n.select(),document.execCommand("copy"),document.body.removeChild(n)}t.textContent="复制成功",setTimeout((()=>t.textContent=o),500)}})),document.addEventListener("DOMContentLoaded",(function(){$uploadFile.addEventListener("change",(function(){handleFileSelection(this.files)})),$uploadButton.addEventListener("click",(function(){if($uploadFile.files.length>0)for(let e=0;e<$uploadFile.files.length;e++)uploadFile($uploadFile.files[e]);else alert("请至少选择一个文件")}));let e=0;document.documentElement.addEventListener("dragover",(function(e){e.preventDefault()})),document.documentElement.addEventListener("dragenter",(function(t){t.preventDefault(),0===e&&(document.documentElement.style.backgroundColor="rgba(0, 123, 255, 0.1)"),e++})),document.documentElement.addEventListener("dragleave",(function(t){e--,0===e&&(document.documentElement.style.backgroundColor="transparent")})),document.documentElement.addEventListener("drop",(function(t){t.preventDefault(),document.documentElement.style.backgroundColor="transparent",$uploadFile.files=t.dataTransfer.files,handleFileSelection($uploadFile.files),e=0}))}));const handleFileSelection=e=>{e.length>0?(1===e.length?$uploadFileLabel.textContent="已选择文件: "+e[0].name:$uploadFileLabel.textContent=`已选择${e.length}个文件`,$uploadFileLabel.style.backgroundColor="#0056b3"):($uploadFileLabel.textContent="选择文件或拖拽到此区域",$uploadFileLabel.style.backgroundColor="#007BFF")}</script> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{{define "public/header"}} | ||
<!doctype html><meta charset=UTF-8><title>tgState</title><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1"><style>#uploadFileLabel{width:280px;height:100px;border:2.5px dashed #ccc;border-radius:20px;text-align:center;padding:20px;font-size:20px;margin:20px auto;cursor:pointer;display:block;background-color:#007bff;color:#fff}#uploadButton{width:260px;border:2.5px dashed #ccc;border-radius:20px;padding:20px;margin:20px auto;cursor:pointer;font-size:20px;display:block;background-color:#007bff;color:#fff}body{text-align:center}h1{color:#333}.custom-file-input{display:none}.custom-file-label{background-color:#007bff;color:#fff;padding:10px 20px;cursor:pointer}.custom-file-label:hover{background-color:#0056b3}#uploadButton{background-color:#007bff;color:#fff;padding:10px 20px;border:none;cursor:pointer}#uploadButton[disabled]{background-color:#ccc;cursor:not-allowed}#uploadButton:hover{background-color:#0056b3}#response{margin-top:20px;padding:10px}.response-item{margin-bottom:10px;padding:10px;border-radius:5px}.response-success{background-color:#d4edda;border-color:#c3e6cb;color:#155724}.response-error{background-color:#f8d7da;border-color:#f5c6cb;color:#721c24}#loading{display:none}.copy-code{margin:5px}.copy-links{margin-top:5px}#uploadButton[disabled]:hover{background-color:#ccc;cursor:not-allowed}.password{margin:0;padding:0;display:flex;justify-content:center;align-items:center;height:100vh;background-color:#f2f2f2}.form-container{text-align:center;background-color:#fff;padding:20px;border-radius:10px;box-shadow:0 0 10px rgba(0,0,0,.2)}.form-input{width:300px;padding:10px;margin:10px;border:1px solid #ccc;border-radius:5px;font-size:16px}.form-button{padding:10px 20px;background-color:#007bff;color:#fff;border:none;border-radius:5px;font-size:18px;cursor:pointer}@media (max-width:465px){.form-container{padding:0;border-radius:0}.form-input{margin-top:30px}}</style> | ||
<!doctype html><meta charset=UTF-8><title>tgState</title><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1"><style>#uploadFileLabel{width:280px;height:100px;border:2.5px dashed #ccc;border-radius:20px;text-align:center;padding:20px;font-size:20px;margin:20px auto;cursor:pointer;display:block;background-color:#007bff;color:#fff}#uploadButton{width:260px;border:2.5px dashed #ccc;border-radius:20px;padding:20px;margin:20px auto;cursor:pointer;font-size:20px;display:block;background-color:#007bff;color:#fff}body{text-align:center}h1{color:#333}p{display:inline}.custom-file-input{display:none}.custom-file-label{background-color:#007bff;color:#fff;padding:10px 20px;cursor:pointer}.custom-file-label:hover{background-color:#0056b3}#uploadButton{background-color:#007bff;color:#fff;padding:10px 20px;border:none;cursor:pointer}#uploadButton[disabled]{background-color:#ccc;cursor:not-allowed}#uploadButton:hover{background-color:#0056b3}#response{margin-top:20px;padding:10px}.response-item{margin-bottom:10px;padding:10px;border-radius:10px}.response-success{background-color:#d4edda;border-color:#c3e6cb;color:#155724}.response-error{background-color:#f8d7da;border-color:#f5c6cb;color:#721c24}#loading{display:none}.copy-code{margin:5px}.copy-links{margin-top:5px}#uploadButton[disabled]:hover{background-color:#ccc;cursor:not-allowed}.password{margin:0;padding:0;display:flex;justify-content:center;align-items:center;height:100vh;background-color:#f2f2f2}.form-container{text-align:center;background-color:#fff;padding:20px;border-radius:10px;box-shadow:0 0 10px rgba(0,0,0,.2)}.form-input{width:300px;padding:10px;margin:10px;border:1px solid #ccc;border-radius:5px;font-size:16px}.form-button{padding:10px 20px;background-color:#007bff;color:#fff;border:none;border-radius:5px;font-size:18px;cursor:pointer}@media (max-width:465px){.form-container{padding:0;border-radius:0}.form-input{margin-top:30px}}</style> | ||
{{end}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.