Skip to content

Commit

Permalink
[F] Fix file download
Browse files Browse the repository at this point in the history
  • Loading branch information
hykilpikonna committed Feb 12, 2024
1 parent b059e02 commit c408004
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/views/FileView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ import {Emit, Prop, Ref} from "vue-property-decorator";
import {durationFmt, sizeFmt} from "@/logic/formatter";
import fileDownload from "js-file-download"
function downloadURI(uri: string, name: string) {
let link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
@Options({components: {
Location: defineAsyncComponent(() => import("./Location.vue")),
Poll: defineAsyncComponent(() => import("./Poll.vue")),
Expand All @@ -78,9 +87,12 @@ export default class FileView extends Vue
fileThumbClick()
{
// Is regular file, download
if (!this.f.media_type)
return fileDownload(this.f.url, this.f.url.split("/").slice(-1)[0])
if (!this.f.media_type) {
console.log(`Downloading file: ${this.f.url}`)
return downloadURI(this.f.url, this.f.url.split("/").slice(-1)[0])
// fileDownload downloads content directly, not URL
// return fileDownload(this.f.url, this.f.url.split("/").slice(-1)[0])
}
// Is audio, emit event
this.play()
}
Expand Down

0 comments on commit c408004

Please sign in to comment.