add Custom link Option at share panel

(cherry picked from commit d7ff423e04ad0e2e66e1011c15c0eb42f8bb65ef)
(cherry picked from commit 382a122847868c938ada4bcf5e2f6f8d331cb0d1)
This commit is contained in:
langren1353 2023-04-07 17:09:01 +08:00
parent 1a5b999545
commit 8a205b14d8
27 changed files with 141 additions and 17 deletions

View File

@ -15,16 +15,37 @@ export async function remove(hash) {
}); });
} }
export async function create(url, password = "", expires = "", unit = "hours") { export async function create(
config = {
url: "",
password: "",
expires: "",
unit: "hours",
custom: false,
customLink: "",
}
) {
let {
url,
password = "",
expires = "",
unit = "hours",
custom = false,
customLink = "",
} = config;
url = removePrefix(url); url = removePrefix(url);
url = `/api/share${url}`; url = `/api/share${url}`;
if (expires !== "") { if (expires !== "") {
url += `?expires=${expires}&unit=${unit}`; url += `?expires=${expires}&unit=${unit}`;
} }
let body = "{}"; let body = {
if (password != "" || expires !== "" || unit !== "hours") { custom,
body = JSON.stringify({ password: password, expires: expires, unit: unit }); customLink: customLink,
};
if (password !== "" || expires !== "" || unit !== "hours") {
Object.assign(body, { password: password, expires: expires, unit: unit });
} }
body = JSON.stringify(body);
return fetchJSON(url, { return fetchJSON(url, {
method: "POST", method: "POST",
body: body, body: body,

View File

@ -68,6 +68,27 @@
<template v-else> <template v-else>
<div class="card-content"> <div class="card-content">
<div>
<span class="margin-tb-1em">
<label for="customLink" style="margin-right: 5px">{{
$t("settings.shareCustomLink")
}}</label>
<input
id="customLink"
class="input display-inline"
type="checkbox"
v-model="custom"
@change="customChange"
/>
</span>
<input
class="input input--block"
:class="{ 'disable-gray': !custom }"
:disabled="!custom"
type="text"
v-model="customLink"
/>
</div>
<p>{{ $t("settings.shareDuration") }}</p> <p>{{ $t("settings.shareDuration") }}</p>
<div class="input-group input"> <div class="input-group input">
<input <input
@ -90,6 +111,7 @@
class="input input--block" class="input input--block"
type="password" type="password"
v-model.trim="password" v-model.trim="password"
autocomplete="new-password"
/> />
</div> </div>
@ -130,6 +152,8 @@ export default {
links: [], links: [],
clip: null, clip: null,
password: "", password: "",
custom: false,
customLink: "",
listing: true, listing: true,
}; };
}, },
@ -148,6 +172,13 @@ export default {
return this.req.items[this.selected[0]].url; return this.req.items[this.selected[0]].url;
}, },
name() {
if (this.selectedCount === 0 || this.selectedCount > 1) {
// This shouldn't happen.
return;
}
return this.req.items[this.selected[0]].name;
},
}, },
async beforeMount() { async beforeMount() {
try { try {
@ -155,7 +186,7 @@ export default {
this.links = links; this.links = links;
this.sort(); this.sort();
if (this.links.length == 0) { if (this.links.length === 0) {
this.listing = false; this.listing = false;
} }
} catch (e) { } catch (e) {
@ -167,23 +198,38 @@ export default {
this.clip.on("success", () => { this.clip.on("success", () => {
this.$showSuccess(this.$t("success.linkCopied")); this.$showSuccess(this.$t("success.linkCopied"));
}); });
this.customLink = this.name;
}, },
beforeDestroy() { beforeDestroy() {
this.clip.destroy(); this.clip.destroy();
}, },
methods: { methods: {
submit: async function () { submit: async function () {
let isPermanent = !this.time || this.time == 0; let isPermanent = !this.time || this.time === 0;
try { try {
let res = null; let query = {
url: this.url,
password: this.password,
custom: this.custom,
customLink: this.customLink,
};
if (isPermanent) { if (this.custom) {
res = await api.create(this.url, this.password); if (!this.checkCustomLink()) {
} else { alert("自定义链接,只支持英文和数字");
res = await api.create(this.url, this.password, this.time, this.unit); return;
}
} }
if (!isPermanent) {
Object.assign(query, {
expires: this.time,
unit: this.unit,
});
}
const res = await api.create(query);
this.links.push(res); this.links.push(res);
this.sort(); this.sort();
@ -196,6 +242,18 @@ export default {
this.$showError(e); this.$showError(e);
} }
}, },
checkCustomLink() {
if (this.custom) {
return /[\w]/.test(this.customLink);
}
return true;
},
customChange(tf) {
console.log("数据发生变化");
if (tf) {
this.customLink = this.name;
}
},
deleteLink: async function (event, link) { deleteLink: async function (event, link) {
event.preventDefault(); event.preventDefault();
try { try {
@ -232,3 +290,16 @@ export default {
}, },
}; };
</script> </script>
<style scoped>
.display-inline {
display: inline;
}
.margin-tb-1em {
display: block;
margin-bottom: 1em;
}
.disable-gray {
background-color: #dbdbdb;
cursor: not-allowed;
}
</style>

View File

@ -216,6 +216,7 @@
"scope": "نطاق", "scope": "نطاق",
"settingsUpdated": "تم تعديل الإعدادات", "settingsUpdated": "تم تعديل الإعدادات",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "عرف الرابط",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -226,6 +226,7 @@
"setDateFormat": "Exaktes Datumsformat setzen", "setDateFormat": "Exaktes Datumsformat setzen",
"settingsUpdated": "Einstellungen aktualisiert!", "settingsUpdated": "Einstellungen aktualisiert!",
"shareDuration": "Dauer", "shareDuration": "Dauer",
"shareCustomLink": "Benutzerdefinierter Link",
"shareManagement": "Freigaben verwalten", "shareManagement": "Freigaben verwalten",
"shareDeleted": "Freigabe gelöscht!", "shareDeleted": "Freigabe gelöscht!",
"singleClick": "Einfacher Klick zum Öffnen von Dateien und Ordnern", "singleClick": "Einfacher Klick zum Öffnen von Dateien und Ordnern",

View File

@ -229,6 +229,7 @@
"setDateFormat": "Set exact date format", "setDateFormat": "Set exact date format",
"settingsUpdated": "Settings updated!", "settingsUpdated": "Settings updated!",
"shareDuration": "Share Duration", "shareDuration": "Share Duration",
"shareCustomLink": "Custom Link",
"shareManagement": "Share Management", "shareManagement": "Share Management",
"shareDeleted": "Share deleted!", "shareDeleted": "Share deleted!",
"singleClick": "Use single clicks to open files and directories", "singleClick": "Use single clicks to open files and directories",

View File

@ -229,6 +229,7 @@
"setDateFormat": "Establecer el formato exacto de la fecha", "setDateFormat": "Establecer el formato exacto de la fecha",
"settingsUpdated": "¡Ajustes actualizados!", "settingsUpdated": "¡Ajustes actualizados!",
"shareDuration": "Compartir Duración", "shareDuration": "Compartir Duración",
"shareCustomLink": "Liens personnalisés",
"shareManagement": "Gestión Compartida", "shareManagement": "Gestión Compartida",
"shareDeleted": "¡Recurso compartido eliminado!", "shareDeleted": "¡Recurso compartido eliminado!",
"singleClick": "Utilice un solo clic para abrir archivos y directorios", "singleClick": "Utilice un solo clic para abrir archivos y directorios",

View File

@ -226,6 +226,7 @@
"setDateFormat": "Définir le format de la date", "setDateFormat": "Définir le format de la date",
"settingsUpdated": "Les paramètres ont été mis à jour !", "settingsUpdated": "Les paramètres ont été mis à jour !",
"shareDuration": "Durée du partage", "shareDuration": "Durée du partage",
"shareCustomLink": "",
"shareManagement": "Gestion des partages", "shareManagement": "Gestion des partages",
"shareDeleted": "Partage supprimé !", "shareDeleted": "Partage supprimé !",
"singleClick": "Utiliser un simple clic pour ouvrir les fichiers et les dossiers", "singleClick": "Utiliser un simple clic pour ouvrir les fichiers et les dossiers",

View File

@ -228,6 +228,7 @@
"setDateFormat": "הגדר פורמט תאריך", "setDateFormat": "הגדר פורמט תאריך",
"settingsUpdated": "ההגדרות עודכנו!", "settingsUpdated": "ההגדרות עודכנו!",
"shareDuration": "משך השיתוף", "shareDuration": "משך השיתוף",
"shareCustomLink": "Aangepaste koppeling",
"shareManagement": "ניהול שיתוף", "shareManagement": "ניהול שיתוף",
"shareDeleted": "שיתוף נמחק!", "shareDeleted": "שיתוף נמחק!",
"singleClick": "השתמש בלחיצות בודדות כדי לפתוח קבצים ותקיות", "singleClick": "השתמש בלחיצות בודדות כדי לפתוח קבצים ותקיות",

View File

@ -228,6 +228,7 @@
"setDateFormat": "Pontos dátumformátum beállítása", "setDateFormat": "Pontos dátumformátum beállítása",
"settingsUpdated": "Beállítások frissítve!", "settingsUpdated": "Beállítások frissítve!",
"shareDuration": "Megosztás időtartama", "shareDuration": "Megosztás időtartama",
"shareCustomLink": "Egyéni kapcsolat",
"shareManagement": "Megosztáskezelés", "shareManagement": "Megosztáskezelés",
"shareDeleted": "Megosztás törölve!", "shareDeleted": "Megosztás törölve!",
"singleClick": "Fájlok és könyvtárak megnyitása egyetlen kattintással", "singleClick": "Fájlok és könyvtárak megnyitása egyetlen kattintással",

View File

@ -216,6 +216,7 @@
"scope": "Sýn notandans", "scope": "Sýn notandans",
"settingsUpdated": "Stillingar vistaðar!", "settingsUpdated": "Stillingar vistaðar!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -216,6 +216,7 @@
"scope": "Scope", "scope": "Scope",
"settingsUpdated": "Impostazioni aggiornate!", "settingsUpdated": "Impostazioni aggiornate!",
"shareDuration": "Durata della condivisione", "shareDuration": "Durata della condivisione",
"shareCustomLink": "Link personalizzato",
"shareManagement": "Gestione delle condivisioni", "shareManagement": "Gestione delle condivisioni",
"singleClick": "Usa un singolo click per aprire file e cartelle", "singleClick": "Usa un singolo click per aprire file e cartelle",
"themes": { "themes": {

View File

@ -216,6 +216,7 @@
"scope": "範囲", "scope": "範囲",
"settingsUpdated": "設定は更新されました!", "settingsUpdated": "設定は更新されました!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "カスタムリンク",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -216,6 +216,7 @@
"scope": "범위", "scope": "범위",
"settingsUpdated": "설정 수정됨!", "settingsUpdated": "설정 수정됨!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "사용자 지정 링크",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -216,6 +216,7 @@
"scope": "Scope", "scope": "Scope",
"settingsUpdated": "Instellingen bijgewerkt!", "settingsUpdated": "Instellingen bijgewerkt!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "Likna usleggem",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -217,6 +217,7 @@
"scope": "Zakres", "scope": "Zakres",
"settingsUpdated": "Uprawnienia Zapisane!", "settingsUpdated": "Uprawnienia Zapisane!",
"shareDuration": "Okres udostępniania", "shareDuration": "Okres udostępniania",
"shareCustomLink": "",
"shareManagement": "Zarządzanie udostępnianiem", "shareManagement": "Zarządzanie udostępnianiem",
"singleClick": "Pojedyncze kliknięcie", "singleClick": "Pojedyncze kliknięcie",
"themes": { "themes": {

View File

@ -229,6 +229,7 @@
"setDateFormat": "Definir formato exato de data", "setDateFormat": "Definir formato exato de data",
"settingsUpdated": "Configurações atualizadas!", "settingsUpdated": "Configurações atualizadas!",
"shareDuration": "Duração do compartilhamento", "shareDuration": "Duração do compartilhamento",
"shareCustomLink": "",
"shareManagement": "Gerenciamento do compartilhamento", "shareManagement": "Gerenciamento do compartilhamento",
"shareDeleted": "Compartilhamento apagado!", "shareDeleted": "Compartilhamento apagado!",
"singleClick": "Usar clique único para abrir arquivos e diretórios", "singleClick": "Usar clique único para abrir arquivos e diretórios",

View File

@ -216,6 +216,7 @@
"scope": "Base", "scope": "Base",
"settingsUpdated": "Configurações atualizadas!", "settingsUpdated": "Configurações atualizadas!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -216,6 +216,7 @@
"scope": "Domeniu", "scope": "Domeniu",
"settingsUpdated": "Setări actualizate!", "settingsUpdated": "Setări actualizate!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "Legătură personalizată",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -225,6 +225,7 @@
"setDateFormat": "Установить точный формат даты", "setDateFormat": "Установить точный формат даты",
"settingsUpdated": "Настройки применены!", "settingsUpdated": "Настройки применены!",
"shareDuration": "Время расшаренной ссылки", "shareDuration": "Время расшаренной ссылки",
"shareCustomLink": "Настройка ссылок",
"shareManagement": "Управление расшаренными ссылками", "shareManagement": "Управление расшаренными ссылками",
"shareDeleted": "Расшаренная ссылка удалена!", "shareDeleted": "Расшаренная ссылка удалена!",
"singleClick": "Открытие файлов и каталогов одним кликом", "singleClick": "Открытие файлов и каталогов одним кликом",

View File

@ -224,6 +224,7 @@
"scope": "Scope", "scope": "Scope",
"settingsUpdated": "Nastavenia upravené!", "settingsUpdated": "Nastavenia upravené!",
"shareDuration": "Trvanie zdieľania", "shareDuration": "Trvanie zdieľania",
"shareCustomLink": "",
"shareManagement": "Správa zdieľania", "shareManagement": "Správa zdieľania",
"shareDeleted": "Zdieľanie odstránené!", "shareDeleted": "Zdieľanie odstránené!",
"singleClick": "Používať jeden klik na otváranie súborov a priečinkov", "singleClick": "Používať jeden klik na otváranie súborov a priečinkov",

View File

@ -216,6 +216,7 @@
"scope": "Omfattning", "scope": "Omfattning",
"settingsUpdated": "Inställning uppdaterad!", "settingsUpdated": "Inställning uppdaterad!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -222,6 +222,7 @@
"scope": "Kapsam", "scope": "Kapsam",
"settingsUpdated": "Ayarlar güncellendi!", "settingsUpdated": "Ayarlar güncellendi!",
"shareDuration": "Paylaşım süresi", "shareDuration": "Paylaşım süresi",
"shareCustomLink": "",
"shareManagement": "Paylaşım yönetimi", "shareManagement": "Paylaşım yönetimi",
"shareDeleted": "Paylaşım silindi!", "shareDeleted": "Paylaşım silindi!",
"singleClick": "Dosyaları ve dizinleri açmak için tek tıklamayı kullanın", "singleClick": "Dosyaları ve dizinleri açmak için tek tıklamayı kullanın",

View File

@ -225,6 +225,7 @@
"setDateFormat": "Встановити точний формат дати", "setDateFormat": "Встановити точний формат дати",
"settingsUpdated": "Налаштування застосовані!", "settingsUpdated": "Налаштування застосовані!",
"shareDuration": "Тривалість спільного посилання", "shareDuration": "Тривалість спільного посилання",
"shareCustomLink": "",
"shareManagement": "Управління спільними посиланнями", "shareManagement": "Управління спільними посиланнями",
"shareDeleted": "Спільне посилання видалено!", "shareDeleted": "Спільне посилання видалено!",
"singleClick": "Відкриття файлів та каталогів одним кліком", "singleClick": "Відкриття файлів та каталогів одним кліком",

View File

@ -225,6 +225,7 @@
"setDateFormat": "显示精确的日期格式", "setDateFormat": "显示精确的日期格式",
"settingsUpdated": "设置已更新!", "settingsUpdated": "设置已更新!",
"shareDuration": "分享期限", "shareDuration": "分享期限",
"shareCustomLink": "自定义链接",
"shareManagement": "分享管理", "shareManagement": "分享管理",
"shareDeleted": "分享已删除!", "shareDeleted": "分享已删除!",
"singleClick": "使用单击来打开文件和目录", "singleClick": "使用单击来打开文件和目录",

View File

@ -216,6 +216,7 @@
"scope": "目錄範圍", "scope": "目錄範圍",
"settingsUpdated": "設定已更新!", "settingsUpdated": "設定已更新!",
"shareDuration": "", "shareDuration": "",
"shareCustomLink": "自定義連結",
"shareManagement": "", "shareManagement": "",
"singleClick": "", "singleClick": "",
"themes": { "themes": {

View File

@ -90,13 +90,19 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
defer r.Body.Close() defer r.Body.Close()
} }
bytes := make([]byte, 6) //nolint:gomnd str := ""
_, err := rand.Read(bytes) if body.Custom {
if err != nil { str = body.CustomLink
return http.StatusInternalServerError, err } else {
bytes := make([]byte, 6) //nolint:gomnd
_, err := rand.Read(bytes)
if err != nil {
return http.StatusInternalServerError, err
}
str = base64.URLEncoding.EncodeToString(bytes)
} }
str := base64.URLEncoding.EncodeToString(bytes)
var expire int64 = 0 var expire int64 = 0

View File

@ -4,6 +4,9 @@ type CreateBody struct {
Password string `json:"password"` Password string `json:"password"`
Expires string `json:"expires"` Expires string `json:"expires"`
Unit string `json:"unit"` Unit string `json:"unit"`
Custom bool `json:"custom"`
CustomLink string `json:"customLink"`
} }
// Link is the information needed to build a shareable link. // Link is the information needed to build a shareable link.