Proposal for public folders
This commit is contained in:
parent
fc5e2247f6
commit
59de83f27d
@ -1,27 +1,33 @@
|
||||
<template>
|
||||
<div class="share" v-if="loaded">
|
||||
<a target="_blank" :href="link">
|
||||
<a target="_blank" :href="link" v-if="!file.isDir">
|
||||
<div class="share__box">
|
||||
<div class="share__box__download" v-if="file.isDir">{{ $t('download.downloadFolder') }}</div>
|
||||
<div class="share__box__download" v-else>{{ $t('download.downloadFile') }}</div>
|
||||
<div class="share__box__download">{{ $t('download.downloadFile') }}</div>
|
||||
<div class="share__box__info">
|
||||
<svg v-if="file.isDir" fill="#40c4ff" height="150" viewBox="0 0 24 24" width="150" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M10 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2h-8l-2-2z"/>
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
</svg>
|
||||
<svg v-else fill="#40c4ff" height="150" viewBox="0 0 24 24" width="150" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M6 2c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6H6zm7 7V3.5L18.5 9H13z"/>
|
||||
<path d="M0 0h24v24H0z" fill="none"/>
|
||||
<svg
|
||||
fill="#40c4ff"
|
||||
height="150"
|
||||
viewBox="0 0 24 24"
|
||||
width="150"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M6 2c-1.1 0-1.99.9-1.99 2L4 20c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6H6zm7 7V3.5L18.5 9H13z"
|
||||
/>
|
||||
<path d="M0 0h24v24H0z" fill="none" />
|
||||
</svg>
|
||||
<h1 class="share__box__title">{{ file.name }}</h1>
|
||||
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<listing></listing>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Listing from '@/components/files/Listing'
|
||||
|
||||
import { share as api } from '@/api'
|
||||
import { baseURL } from '@/utils/constants'
|
||||
import QrcodeVue from 'qrcode.vue'
|
||||
@ -29,12 +35,14 @@ import QrcodeVue from 'qrcode.vue'
|
||||
export default {
|
||||
name: 'share',
|
||||
components: {
|
||||
QrcodeVue
|
||||
QrcodeVue,
|
||||
Listing
|
||||
},
|
||||
data: () => ({
|
||||
loaded: false,
|
||||
notFound: false,
|
||||
file: null
|
||||
file: null,
|
||||
dirContent: null
|
||||
}),
|
||||
watch: {
|
||||
'$route': 'fetchData'
|
||||
@ -57,6 +65,29 @@ export default {
|
||||
fetchData: async function () {
|
||||
try {
|
||||
this.file = await api.getHash(this.hash)
|
||||
|
||||
if (this.file.isDir) {
|
||||
const tmpPath = this.hash.split('/')
|
||||
const hash = tmpPath.shift();
|
||||
const relativePath = tmpPath.join('/');
|
||||
|
||||
const items = await fetch('/api/public/resources/' + hash, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Relative-Path': relativePath
|
||||
}
|
||||
}).then((ret) => {
|
||||
if (ret.status === 200) {
|
||||
return ret.json();
|
||||
}
|
||||
}).then((file) => {
|
||||
return file.items
|
||||
});
|
||||
console.log(items);
|
||||
|
||||
this.dirContent = items;
|
||||
}
|
||||
|
||||
this.loaded = true
|
||||
} catch (e) {
|
||||
this.notFound = true
|
||||
|
||||
@ -64,6 +64,7 @@ func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler
|
||||
public := api.PathPrefix("/public").Subrouter()
|
||||
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
||||
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).Methods("GET")
|
||||
public.PathPrefix("/resources").Handler(monkey(publicShareFolderHandler, "/api/public/resources/")).Methods("GET")
|
||||
|
||||
return stripPrefix(server.BaseURL, r), nil
|
||||
}
|
||||
|
||||
@ -58,3 +58,22 @@ var publicDlHandler = withHashFile(func(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
return rawDirHandler(w, r, d, file)
|
||||
})
|
||||
|
||||
var publicShareFolderHandler = withHashFile(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
|
||||
baseFolder := d.raw.(*files.FileInfo)
|
||||
|
||||
file, err := files.NewFileInfo(files.FileOptions{
|
||||
Fs: d.user.Fs,
|
||||
Path: baseFolder.Path + "/" + r.Header.Get("Relative-Path"),
|
||||
Modify: d.user.Perm.Modify,
|
||||
Expand: true,
|
||||
Checker: d,
|
||||
})
|
||||
if err != nil {
|
||||
return errToStatus(err), err
|
||||
}
|
||||
|
||||
file.Listing.Sorting = d.user.Sorting
|
||||
file.Listing.ApplySort()
|
||||
return renderJSON(w, r, file)
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user