mirror of
				https://github.com/filebrowser/filebrowser.git
				synced 2025-10-31 17:23:09 +00:00 
			
		
		
		
	feat: improved sharing prompt
This commit is contained in:
		
							parent
							
								
									a809404ce1
								
							
						
					
					
						commit
						1819377897
					
				| @ -119,8 +119,8 @@ nav > div { | |||||||
| .dashboard p label { | .dashboard p label { | ||||||
|   color: var(--textPrimary); |   color: var(--textPrimary); | ||||||
| } | } | ||||||
| .card#share ul li input, | .card#share input, | ||||||
| .card#share ul li select, | .card#share select, | ||||||
| .input { | .input { | ||||||
|   background: var(--surfaceSecondary); |   background: var(--surfaceSecondary); | ||||||
|   color: var(--textPrimary); |   color: var(--textPrimary); | ||||||
|  | |||||||
| @ -4,61 +4,82 @@ | |||||||
|       <h2>{{ $t('buttons.share') }}</h2> |       <h2>{{ $t('buttons.share') }}</h2> | ||||||
|     </div> |     </div> | ||||||
| 
 | 
 | ||||||
|  |     <template v-if="listing"> | ||||||
|       <div class="card-content"> |       <div class="card-content"> | ||||||
|       <ul> |         <table> | ||||||
|  |           <tr> | ||||||
|  |             <th>#</th> | ||||||
|  |             <th>{{ $t('settings.shareDuration') }}</th> | ||||||
|  |             <th></th> | ||||||
|  |             <th></th> | ||||||
|  |           </tr> | ||||||
| 
 | 
 | ||||||
|         <li v-for="link in links" :key="link.hash"> |           <tr v-for="link in links" :key="link.hash"> | ||||||
|           <a :href="buildLink(link.hash)" target="_blank"> |             <td>{{ link.hash }}</td> | ||||||
|  |             <td> | ||||||
|               <template v-if="link.expire !== 0">{{ humanTime(link.expire) }}</template> |               <template v-if="link.expire !== 0">{{ humanTime(link.expire) }}</template> | ||||||
|               <template v-else>{{ $t('permanent') }}</template> |               <template v-else>{{ $t('permanent') }}</template> | ||||||
|           </a> |             </td> | ||||||
| 
 |             <td class="small"> | ||||||
|           <button class="action" |  | ||||||
|             @click="deleteLink($event, link)" |  | ||||||
|             :aria-label="$t('buttons.delete')" |  | ||||||
|             :title="$t('buttons.delete')"><i class="material-icons">delete</i></button> |  | ||||||
| 
 |  | ||||||
|               <button class="action copy-clipboard" |               <button class="action copy-clipboard" | ||||||
|                 :data-clipboard-text="buildLink(link.hash)" |                 :data-clipboard-text="buildLink(link.hash)" | ||||||
|                 :aria-label="$t('buttons.copyToClipboard')" |                 :aria-label="$t('buttons.copyToClipboard')" | ||||||
|                 :title="$t('buttons.copyToClipboard')"><i class="material-icons">content_paste</i></button> |                 :title="$t('buttons.copyToClipboard')"><i class="material-icons">content_paste</i></button> | ||||||
|         </li> |             </td> | ||||||
| 
 |             <td class="small"> | ||||||
|         <li v-if="!hasPermanent"> |               <button class="action" | ||||||
|           <div> |                 @click="deleteLink($event, link)" | ||||||
|             <input type="password" :placeholder="$t('prompts.optionalPassword')" v-model="passwordPermalink"> |                 :aria-label="$t('buttons.delete')" | ||||||
|             <a @click="getPermalink" :aria-label="$t('buttons.permalink')">{{ $t('buttons.permalink') }}</a> |                 :title="$t('buttons.delete')"><i class="material-icons">delete</i></button> | ||||||
|  |             </td> | ||||||
|  |           </tr> | ||||||
|  |         </table> | ||||||
|       </div> |       </div> | ||||||
|         </li> |  | ||||||
| 
 | 
 | ||||||
|         <li> |       <div class="card-action"> | ||||||
|  |         <button class="button button--flat button--grey" | ||||||
|  |           @click="$store.commit('closeHovers')" | ||||||
|  |           :aria-label="$t('buttons.close')" | ||||||
|  |           :title="$t('buttons.close')">{{ $t('buttons.close') }}</button> | ||||||
|  |         <button class="button button--flat button--blue" | ||||||
|  |           @click="() => switchListing()" | ||||||
|  |           :aria-label="$t('buttons.new')" | ||||||
|  |           :title="$t('buttons.new')">{{ $t('buttons.new') }}</button> | ||||||
|  |       </div> | ||||||
|  |     </template> | ||||||
|  | 
 | ||||||
|  |     <template v-else> | ||||||
|  |       <div class="card-content"> | ||||||
|  |         <p>{{ $t('settings.shareDuration') }}</p> | ||||||
|  |         <div class="input-group input"> | ||||||
|             <input v-focus |             <input v-focus | ||||||
|               type="number" |               type="number" | ||||||
|               max="2147483647" |               max="2147483647" | ||||||
|             min="0" |               min="1" | ||||||
|               @keyup.enter="submit" |               @keyup.enter="submit" | ||||||
|               v-model.trim="time"> |               v-model.trim="time"> | ||||||
|           <select v-model="unit" :aria-label="$t('time.unit')"> |             <select class="right" v-model="unit" :aria-label="$t('time.unit')"> | ||||||
|               <option value="seconds">{{ $t('time.seconds') }}</option> |               <option value="seconds">{{ $t('time.seconds') }}</option> | ||||||
|               <option value="minutes">{{ $t('time.minutes') }}</option> |               <option value="minutes">{{ $t('time.minutes') }}</option> | ||||||
|               <option value="hours">{{ $t('time.hours') }}</option> |               <option value="hours">{{ $t('time.hours') }}</option> | ||||||
|               <option value="days">{{ $t('time.days') }}</option> |               <option value="days">{{ $t('time.days') }}</option> | ||||||
|             </select> |             </select> | ||||||
|           <input type="password" :placeholder="$t('prompts.optionalPassword')" v-model="password"> |         </div> | ||||||
|           <button class="action" |         <p>{{ $t('prompts.optionalPassword') }}</p> | ||||||
|             @click="submit" |         <input class="input input--block" type="password" v-model.trim="password"> | ||||||
|             :aria-label="$t('buttons.create')" |  | ||||||
|             :title="$t('buttons.create')"><i class="material-icons">add</i></button> |  | ||||||
|         </li> |  | ||||||
|       </ul> |  | ||||||
|       </div> |       </div> | ||||||
| 
 | 
 | ||||||
|       <div class="card-action"> |       <div class="card-action"> | ||||||
|       <button class="button button--flat" |         <button class="button button--flat button--grey" | ||||||
|         @click="$store.commit('closeHovers')" |           @click="() => switchListing()" | ||||||
|         :aria-label="$t('buttons.close')" |           :aria-label="$t('buttons.cancel')" | ||||||
|         :title="$t('buttons.close')">{{ $t('buttons.close') }}</button> |           :title="$t('buttons.cancel')">{{ $t('buttons.cancel') }}</button> | ||||||
|  |         <button class="button button--flat button--blue" | ||||||
|  |           @click="submit" | ||||||
|  |           :aria-label="$t('buttons.share')" | ||||||
|  |           :title="$t('buttons.share')">{{ $t('buttons.share') }}</button> | ||||||
|       </div> |       </div> | ||||||
|  |     </template> | ||||||
|   </div> |   </div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| @ -75,11 +96,10 @@ export default { | |||||||
|     return { |     return { | ||||||
|       time: '', |       time: '', | ||||||
|       unit: 'hours', |       unit: 'hours', | ||||||
|       hasPermanent: false, |  | ||||||
|       links: [], |       links: [], | ||||||
|       clip: null, |       clip: null, | ||||||
|       password: '', |       password: '', | ||||||
|       passwordPermalink: '' |       listing: true | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   computed: { |   computed: { | ||||||
| @ -104,11 +124,8 @@ export default { | |||||||
|       this.links = links |       this.links = links | ||||||
|       this.sort() |       this.sort() | ||||||
| 
 | 
 | ||||||
|       for (let link of this.links) { |       if (this.links.length == 0) { | ||||||
|         if (link.expire === 0) { |         this.listing = false | ||||||
|           this.hasPermanent = true |  | ||||||
|           break |  | ||||||
|         } |  | ||||||
|       } |       } | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|       this.$showError(e) |       this.$showError(e) | ||||||
| @ -125,22 +142,25 @@ export default { | |||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     submit: async function () { |     submit: async function () { | ||||||
|       if (!this.time) return |       let isPermanent = !this.time || this.time == 0 | ||||||
| 
 | 
 | ||||||
|       try { |       try { | ||||||
|         const res = await api.create(this.url, this.password, this.time, this.unit) |         let res = null | ||||||
|         this.links.push(res) | 
 | ||||||
|         this.sort() |         if (isPermanent) { | ||||||
|       } catch (e) { |           res = await api.create(this.url, this.password) | ||||||
|         this.$showError(e) |         } else { | ||||||
|  |           res = await api.create(this.url, this.password, this.time, this.unit) | ||||||
|         } |         } | ||||||
|     }, | 
 | ||||||
|     getPermalink: async function () { |  | ||||||
|       try { |  | ||||||
|         const res = await api.create(this.url, this.passwordPermalink) |  | ||||||
|         this.links.push(res) |         this.links.push(res) | ||||||
|         this.sort() |         this.sort() | ||||||
|         this.hasPermanent = true | 
 | ||||||
|  |         this.time = '' | ||||||
|  |         this.unit = 'hours' | ||||||
|  |         this.password = '' | ||||||
|  | 
 | ||||||
|  |         this.listing = true | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         this.$showError(e) |         this.$showError(e) | ||||||
|       } |       } | ||||||
| @ -149,8 +169,11 @@ export default { | |||||||
|       event.preventDefault() |       event.preventDefault() | ||||||
|        try { |        try { | ||||||
|         await api.remove(link.hash) |         await api.remove(link.hash) | ||||||
|         if (link.expire === 0) this.hasPermanent = false |  | ||||||
|         this.links = this.links.filter(item => item.hash !== link.hash) |         this.links = this.links.filter(item => item.hash !== link.hash) | ||||||
|  | 
 | ||||||
|  |         if (this.links.length == 0) { | ||||||
|  |           this.listing = false | ||||||
|  |         } | ||||||
|       } catch (e) { |       } catch (e) { | ||||||
|         this.$showError(e) |         this.$showError(e) | ||||||
|       } |       } | ||||||
| @ -167,6 +190,13 @@ export default { | |||||||
|         if (b.expire === 0) return 1 |         if (b.expire === 0) return 1 | ||||||
|         return new Date(a.expire) - new Date(b.expire) |         return new Date(a.expire) - new Date(b.expire) | ||||||
|       }) |       }) | ||||||
|  |     }, | ||||||
|  |     switchListing () { | ||||||
|  |       if (this.links.length == 0 && !this.listing) { | ||||||
|  |         this.$store.commit('closeHovers') | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       this.listing = !this.listing | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -71,8 +71,3 @@ | |||||||
|   text-align: center; |   text-align: center; | ||||||
|   animation: .2s opac forwards; |   animation: .2s opac forwards; | ||||||
| } | } | ||||||
| 
 |  | ||||||
| .share__promt__card { |  | ||||||
|   max-width: max-content !important; |  | ||||||
|   width: auto !important; |  | ||||||
| } |  | ||||||
|  | |||||||
| @ -226,6 +226,18 @@ table tr>*:last-child { | |||||||
|   opacity: 1; |   opacity: 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | .card#share .input-group { | ||||||
|  |   display: flex; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .card#share .input-group * { | ||||||
|  |   border: none; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .card#share .input-group input { | ||||||
|  |   flex: 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| .overlay { | .overlay { | ||||||
|   background-color: rgba(0, 0, 0, 0.5); |   background-color: rgba(0, 0, 0, 0.5); | ||||||
|   position: fixed; |   position: fixed; | ||||||
|  | |||||||
| @ -6,7 +6,6 @@ import ( | |||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"path" |  | ||||||
| 	"sort" | 	"sort" | ||||||
| 	"strconv" | 	"strconv" | ||||||
| 	"strings" | 	"strings" | ||||||
| @ -91,17 +90,6 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request | |||||||
| 		defer r.Body.Close() | 		defer r.Body.Close() | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if body.Expires == "" { |  | ||||||
| 		var err error |  | ||||||
| 		s, err = d.store.Share.GetPermanent(r.URL.Path, d.user.ID) |  | ||||||
| 		if err == nil { |  | ||||||
| 			if _, err := w.Write([]byte(path.Join(d.server.BaseURL, "/share/", s.Hash))); err != nil { |  | ||||||
| 				return http.StatusInternalServerError, err |  | ||||||
| 			} |  | ||||||
| 			return 0, nil |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	bytes := make([]byte, 6) | 	bytes := make([]byte, 6) | ||||||
| 	_, err := rand.Read(bytes) | 	_, err := rand.Read(bytes) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Ramires Viana
						Ramires Viana