Skip to content

Commit

Permalink
Update App.vue
Browse files Browse the repository at this point in the history
  • Loading branch information
ljxi committed Mar 28, 2024
1 parent f27c4f8 commit a78a882
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions assets/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</button>
<Menu
v-model="showMenu"
:items="[{ text: '名称A-Z' }, { text: '大小↑' } ,{ text: '大小↓' }]"
:items="[{ text: '名称A-Z' }, { text: '大小↑' } ,{ text: '大小↓' }, { text: '粘贴' }]"
@click="onMenuClick"
/>
</div>
Expand Down Expand Up @@ -173,6 +173,11 @@
<span>下载</span>
</a>
</li>
<li>
<button @click="clipboard = focusedItem.key">
<span>复制</span>
</button>
</li>
<li>
<button @click="copyLink(`/raw/${focusedItem.key}`)">
<span>复制链接</span>
Expand Down Expand Up @@ -205,6 +210,7 @@ export default {
cwd: new URL(window.location).searchParams.get("p") || "",
files: [],
folders: [],
clipboard: null,
focusedItem: null,
loading: false,
order: null,
Expand Down Expand Up @@ -242,6 +248,13 @@ export default {
navigator.clipboard.writeText(url.toString());
},
async copyPaste(source, target) {
const uploadUrl = `/api/write/items/${target}`;
await axios.put(uploadUrl, "", {
headers: { "x-amz-copy-source": encodeURIComponent(source) },
});
},
async createFolder() {
try {
const folderName = window.prompt("请输入文件夹名称");
Expand Down Expand Up @@ -311,6 +324,8 @@ export default {
case "大小↓":
this.order = "大小↓";
break;
case "粘贴":
return this.pasteFile();
}
this.files.sort((a, b) => {
if (this.order === "大小↑") {
Expand All @@ -334,6 +349,15 @@ export default {
window.open(filePath);
},
async pasteFile() {
if (!this.clipboard) return;
let newName = window.prompt("Rename to:");
if (newName === null) return;
if (newName === "") newName = this.clipboard.split("/").pop();
await this.copyPaste(this.clipboard, `${this.cwd}${newName}`);
this.fetchFiles();
},
async processUploadQueue() {
if (!this.uploadQueue.length) {
this.fetchFiles();
Expand Down Expand Up @@ -404,10 +428,7 @@ export default {
async renameFile(key) {
const newName = window.prompt("重命名为:");
if (!newName) return;
const uploadUrl = `/api/write/items/${this.cwd}${newName}`;
await axios.put(uploadUrl, "", {
headers: { "x-amz-copy-source": encodeURIComponent(key) },
});
await this.copyPaste(key, `${this.cwd}${newName}`);
await axios.delete(`/api/write/items/${key}`);
this.fetchFiles();
},
Expand Down

0 comments on commit a78a882

Please sign in to comment.