Skip to content

Commit dcbc328

Browse files
authored
Merge pull request filebrowser#1133 from ramiresviana/fixes-5
Some fixes and shared view improvements
2 parents b185f9b + 7096b3d commit dcbc328

File tree

8 files changed

+152
-67
lines changed

8 files changed

+152
-67
lines changed

frontend/public/themes/dark.css

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ table th {
191191
}
192192
}
193193

194-
.share__box, .share__box__download {
195-
background: var(--surfaceSecondary) !important;
194+
.share__box {
195+
background: var(--surfacePrimary) !important;
196196
color: var(--textPrimary);
197197
}
198-
.share__box__download {
199-
border-bottom-color: var(--divider);
198+
199+
.share__box__element {
200+
border-top-color: var(--divider);
200201
}

frontend/src/components/files/Preview.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
<i class="material-icons">close</i>
66
</button>
77

8-
<div class="title">
9-
<span>{{ this.name }}</span>
10-
</div>
8+
<div class="title">{{ this.name }}</div>
119

1210
<preview-size-button v-if="isResizeEnabled && this.req.type === 'image'" @change-size="toggleSize" v-bind:size="fullSize" :disabled="loading"></preview-size-button>
1311
<button @click="openMore" id="more" :aria-label="$t('buttons.more')" :title="$t('buttons.more')" class="action">

frontend/src/css/_share.css

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,61 @@
1+
.share {
2+
display: flex;
3+
flex-wrap: wrap;
4+
justify-content: center;
5+
align-items: flex-start;
6+
}
7+
8+
@media (max-width: 736px) {
9+
.share {
10+
display: block;
11+
}
12+
}
13+
114
.share__box {
2-
text-align: center;
315
box-shadow: rgba(0, 0, 0, 0.06) 0px 1px 3px, rgba(0, 0, 0, 0.12) 0px 1px 2px;
416
background: #fff;
5-
display: block;
617
border-radius: 0.2em;
7-
width: 90%;
8-
max-width: 25em;
9-
margin: 6em auto;
18+
margin: 5px;
19+
overflow: hidden;
1020
}
1121

12-
.share__box__download {
13-
width: 100%;
22+
.share__box__header {
1423
padding: 1em;
15-
cursor: pointer;
16-
background: #ffffff;
17-
color: rgba(0, 0, 0, 0.5);
18-
border-bottom: 1px solid rgba(0, 0, 0, 0.05);
24+
text-align: center;
25+
}
26+
27+
.share__box__icon i {
28+
font-size: 10em;
29+
color: #40c4ff;
30+
}
31+
32+
.share__box__center {
33+
text-align: center;
1934
}
2035

2136
.share__box__info {
22-
padding: 2em 3em;
37+
flex: 1 1 auto;
2338
}
2439

25-
.share__box__title {
26-
margin-top: .2em;
27-
overflow: hidden;
28-
text-overflow: ellipsis;
40+
.share__box__element {
41+
padding: 1em;
42+
border-top: 1px solid rgba(0, 0, 0, 0.1);
43+
word-break: break-all;
2944
}
45+
46+
.share__box__items {
47+
text-align: left;
48+
flex: 10 0 25em;
49+
}
50+
51+
.share__box__items #listing.list .item {
52+
cursor: auto;
53+
border-left: 0;
54+
border-right: 0;
55+
border-bottom: 0;
56+
border-top: 1px solid rgba(0, 0, 0, 0.1);
57+
}
58+
59+
.share__box__items #listing.list .item .name {
60+
width: auto;
61+
}

frontend/src/css/styles.css

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,23 @@
119119

120120
#previewer .bar {
121121
width: 100%;
122-
text-align: right;
123122
display: flex;
124123
padding: 0.5em;
125124
height: 3.7em;
126125
}
127126

127+
#previewer .bar > * {
128+
flex: 0 0 auto;
129+
}
130+
128131
#previewer .bar .title {
129-
margin-right: auto;
132+
display: block;
133+
flex: 1 1 auto;
130134
padding: 0 1em;
131-
line-height: 2.7em;
135+
line-height: 2.3em;
132136
overflow: hidden;
133-
word-break: break-word;
137+
text-overflow: ellipsis;
138+
font-size: 1.2em;
134139
color: #fff;
135140
}
136141

@@ -220,10 +225,6 @@
220225
word-break: break-word;
221226
}
222227

223-
#previewer .title span {
224-
font-size: 1.2em;
225-
}
226-
227228
#previewer .loading {
228229
height: 100%;
229230
width: 100%;

frontend/src/views/Share.vue

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,56 @@
11
<template>
22
<div class="share" v-if="loaded">
3-
<a target="_blank" :href="link">
4-
<div class="share__box">
5-
<div class="share__box__download" v-if="file.isDir">{{ $t('download.downloadFolder') }}</div>
6-
<div class="share__box__download" v-else>{{ $t('download.downloadFile') }}</div>
7-
<div class="share__box__info">
8-
<svg v-if="file.isDir" fill="#40c4ff" height="150" viewBox="0 0 24 24" width="150" xmlns="http://www.w3.org/2000/svg">
9-
<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"/>
10-
<path d="M0 0h24v24H0z" fill="none"/>
11-
</svg>
12-
<svg v-else fill="#40c4ff" height="150" viewBox="0 0 24 24" width="150" xmlns="http://www.w3.org/2000/svg">
13-
<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"/>
14-
<path d="M0 0h24v24H0z" fill="none"/>
15-
</svg>
16-
<h1 class="share__box__title">{{ file.name }}</h1>
3+
<div class="share__box share__box__info">
4+
<div class="share__box__header">
5+
{{ file.isDir ? $t('download.downloadFolder') : $t('download.downloadFile') }}
6+
</div>
7+
<div class="share__box__element share__box__center share__box__icon">
8+
<i class="material-icons">{{ file.isDir ? 'folder' : 'insert_drive_file'}}</i>
9+
</div>
10+
<div class="share__box__element">
11+
<strong>{{ $t('prompts.displayName') }}</strong> {{ file.name }}
12+
</div>
13+
<div class="share__box__element">
14+
<strong>{{ $t('prompts.lastModified') }}:</strong> {{ humanTime }}
15+
</div>
16+
<div class="share__box__element">
17+
<strong>{{ $t('prompts.size') }}:</strong> {{ humanSize }}
18+
</div>
19+
<div class="share__box__element share__box__center">
20+
<a target="_blank" :href="link" class="button button--flat">{{ $t('buttons.download') }}</a>
21+
</div>
22+
<div class="share__box__element share__box__center">
1723
<qrcode-vue :value="fullLink" size="200" level="M"></qrcode-vue>
1824
</div>
25+
</div>
26+
<div v-if="file.isDir" class="share__box share__box__items">
27+
<div class="share__box__header" v-if="file.isDir">
28+
{{ $t('files.files') }}
29+
</div>
30+
<div id="listing" class="list">
31+
<div class="item" v-for="(item) in file.items.slice(0, this.showLimit)" :key="base64(item.name)">
32+
<div>
33+
<i class="material-icons">{{ item.isDir ? 'folder' : (item.type==='image') ? 'insert_photo' : 'insert_drive_file' }}</i>
34+
</div>
35+
<div>
36+
<p class="name">{{ item.name }}</p>
37+
</div>
38+
</div>
39+
<div v-if="file.items.length > showLimit" class="item">
40+
<div>
41+
<p class="name"> + {{ file.items.length - showLimit }} </p>
42+
</div>
43+
</div>
1944
</div>
20-
</a>
45+
</div>
2146
</div>
2247
</template>
2348

2449
<script>
2550
import { share as api } from '@/api'
2651
import { baseURL } from '@/utils/constants'
52+
import filesize from 'filesize'
53+
import moment from 'moment'
2754
import QrcodeVue from 'qrcode.vue'
2855
2956
export default {
@@ -34,7 +61,8 @@ export default {
3461
data: () => ({
3562
loaded: false,
3663
notFound: false,
37-
file: null
64+
file: null,
65+
showLimit: 500
3866
}),
3967
watch: {
4068
'$route': 'fetchData'
@@ -52,8 +80,21 @@ export default {
5280
fullLink: function () {
5381
return window.location.origin + this.link
5482
},
83+
humanSize: function () {
84+
if (this.file.isDir) {
85+
return this.file.items.length
86+
}
87+
88+
return filesize(this.file.size)
89+
},
90+
humanTime: function () {
91+
return moment(this.file.modified).fromNow()
92+
}
5593
},
5694
methods: {
95+
base64: function (name) {
96+
return window.btoa(unescape(encodeURIComponent(name)))
97+
},
5798
fetchData: async function () {
5899
try {
59100
this.file = await api.getHash(this.hash)

http/public.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var withHashFile = func(fn handleFunc) handleFunc {
2828
Fs: d.user.Fs,
2929
Path: link.Path,
3030
Modify: d.user.Perm.Modify,
31-
Expand: false,
31+
Expand: true,
3232
Checker: d,
3333
})
3434
if err != nil {
@@ -54,7 +54,15 @@ func ifPathWithName(r *http.Request) string {
5454
}
5555

5656
var publicShareHandler = withHashFile(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
57-
return renderJSON(w, r, d.raw)
57+
file := d.raw.(*files.FileInfo)
58+
59+
if file.IsDir {
60+
file.Listing.Sorting = files.Sorting{By: "name", Asc: false}
61+
file.Listing.ApplySort()
62+
return renderJSON(w, r, file)
63+
}
64+
65+
return renderJSON(w, r, file)
5866
})
5967

6068
var publicDlHandler = withHashFile(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {

http/raw.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,19 @@ func addFile(ar archiver.Writer, d *data, path, commonPath string) error {
116116
}
117117
defer file.Close()
118118

119-
filename := strings.TrimPrefix(path, commonPath)
120-
filename = strings.TrimPrefix(filename, "/")
121-
err = ar.Write(archiver.File{
122-
FileInfo: archiver.FileInfo{
123-
FileInfo: info,
124-
CustomName: filename,
125-
},
126-
ReadCloser: file,
127-
})
128-
if err != nil {
129-
return err
119+
if path != commonPath {
120+
filename := strings.TrimPrefix(path, commonPath)
121+
filename = strings.TrimPrefix(filename, "/")
122+
err = ar.Write(archiver.File{
123+
FileInfo: archiver.FileInfo{
124+
FileInfo: info,
125+
CustomName: filename,
126+
},
127+
ReadCloser: file,
128+
})
129+
if err != nil {
130+
return err
131+
}
130132
}
131133

132134
if info.IsDir() {

http/resource.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"net/url"
99
"os"
10+
"path"
1011
"path/filepath"
1112
"strings"
1213

@@ -122,7 +123,7 @@ var resourcePostPutHandler = withUser(func(w http.ResponseWriter, r *http.Reques
122123
}
123124

124125
err := d.RunHook(func() error {
125-
dir, _ := filepath.Split(r.URL.Path)
126+
dir, _ := path.Split(r.URL.Path)
126127
err := d.user.Fs.MkdirAll(dir, 0775)
127128
if err != nil {
128129
return err
@@ -196,7 +197,8 @@ var resourcePatchHandler = withUser(func(w http.ResponseWriter, r *http.Request,
196197
if !d.user.Perm.Rename {
197198
return errors.ErrPermissionDenied
198199
}
199-
dst = filepath.Clean("/" + dst)
200+
src = path.Clean("/" + src)
201+
dst = path.Clean("/" + dst)
200202

201203
return d.user.Fs.Rename(src, dst)
202204
default:
@@ -221,20 +223,20 @@ func checkParent(src, dst string) error {
221223
return nil
222224
}
223225

224-
func addVersionSuffix(path string, fs afero.Fs) string {
226+
func addVersionSuffix(source string, fs afero.Fs) string {
225227
counter := 1
226-
dir, name := filepath.Split(path)
228+
dir, name := path.Split(source)
227229
ext := filepath.Ext(name)
228230
base := strings.TrimSuffix(name, ext)
229231

230232
for {
231-
if _, err := fs.Stat(path); err != nil {
233+
if _, err := fs.Stat(source); err != nil {
232234
break
233235
}
234236
renamed := fmt.Sprintf("%s(%d)%s", base, counter, ext)
235-
path = filepath.ToSlash(dir) + renamed
237+
source = path.Join(dir, renamed)
236238
counter++
237239
}
238240

239-
return path
241+
return source
240242
}

0 commit comments

Comments
 (0)