Proposal for public folders
This commit is contained in:
parent
fc5e2247f6
commit
59de83f27d
@ -1,27 +1,33 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="share" v-if="loaded">
|
<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">
|
||||||
<div class="share__box__download" v-if="file.isDir">{{ $t('download.downloadFolder') }}</div>
|
<div class="share__box__download">{{ $t('download.downloadFile') }}</div>
|
||||||
<div class="share__box__download" v-else>{{ $t('download.downloadFile') }}</div>
|
|
||||||
<div class="share__box__info">
|
<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">
|
<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"/>
|
fill="#40c4ff"
|
||||||
<path d="M0 0h24v24H0z" fill="none"/>
|
height="150"
|
||||||
</svg>
|
viewBox="0 0 24 24"
|
||||||
<svg v-else fill="#40c4ff" height="150" viewBox="0 0 24 24" width="150" xmlns="http://www.w3.org/2000/svg">
|
width="150"
|
||||||
<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"/>
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
<path d="M0 0h24v24H0z" fill="none"/>
|
>
|
||||||
|
<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>
|
</svg>
|
||||||
<h1 class="share__box__title">{{ file.name }}</h1>
|
<h1 class="share__box__title">{{ file.name }}</h1>
|
||||||
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
|
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
<listing></listing>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Listing from '@/components/files/Listing'
|
||||||
|
|
||||||
import { share as api } from '@/api'
|
import { share as api } from '@/api'
|
||||||
import { baseURL } from '@/utils/constants'
|
import { baseURL } from '@/utils/constants'
|
||||||
import QrcodeVue from 'qrcode.vue'
|
import QrcodeVue from 'qrcode.vue'
|
||||||
@ -29,12 +35,14 @@ import QrcodeVue from 'qrcode.vue'
|
|||||||
export default {
|
export default {
|
||||||
name: 'share',
|
name: 'share',
|
||||||
components: {
|
components: {
|
||||||
QrcodeVue
|
QrcodeVue,
|
||||||
|
Listing
|
||||||
},
|
},
|
||||||
data: () => ({
|
data: () => ({
|
||||||
loaded: false,
|
loaded: false,
|
||||||
notFound: false,
|
notFound: false,
|
||||||
file: null
|
file: null,
|
||||||
|
dirContent: null
|
||||||
}),
|
}),
|
||||||
watch: {
|
watch: {
|
||||||
'$route': 'fetchData'
|
'$route': 'fetchData'
|
||||||
@ -57,6 +65,29 @@ export default {
|
|||||||
fetchData: async function () {
|
fetchData: async function () {
|
||||||
try {
|
try {
|
||||||
this.file = await api.getHash(this.hash)
|
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
|
this.loaded = true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.notFound = true
|
this.notFound = true
|
||||||
|
|||||||
@ -64,6 +64,7 @@ func NewHandler(storage *storage.Storage, server *settings.Server) (http.Handler
|
|||||||
public := api.PathPrefix("/public").Subrouter()
|
public := api.PathPrefix("/public").Subrouter()
|
||||||
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
public.PathPrefix("/dl").Handler(monkey(publicDlHandler, "/api/public/dl/")).Methods("GET")
|
||||||
public.PathPrefix("/share").Handler(monkey(publicShareHandler, "/api/public/share/")).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
|
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)
|
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