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 = `/api/share${url}`;
if (expires !== "") {
url += `?expires=${expires}&unit=${unit}`;
}
let body = "{}";
if (password != "" || expires !== "" || unit !== "hours") {
body = JSON.stringify({ password: password, expires: expires, unit: unit });
let body = {
custom,
customLink: customLink,
};
if (password !== "" || expires !== "" || unit !== "hours") {
Object.assign(body, { password: password, expires: expires, unit: unit });
}
body = JSON.stringify(body);
return fetchJSON(url, {
method: "POST",
body: body,

View File

@ -68,6 +68,27 @@
<template v-else>
<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>
<div class="input-group input">
<input
@ -90,6 +111,7 @@
class="input input--block"
type="password"
v-model.trim="password"
autocomplete="new-password"
/>
</div>
@ -130,6 +152,8 @@ export default {
links: [],
clip: null,
password: "",
custom: false,
customLink: "",
listing: true,
};
},
@ -148,6 +172,13 @@ export default {
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() {
try {
@ -155,7 +186,7 @@ export default {
this.links = links;
this.sort();
if (this.links.length == 0) {
if (this.links.length === 0) {
this.listing = false;
}
} catch (e) {
@ -167,23 +198,38 @@ export default {
this.clip.on("success", () => {
this.$showSuccess(this.$t("success.linkCopied"));
});
this.customLink = this.name;
},
beforeDestroy() {
this.clip.destroy();
},
methods: {
submit: async function () {
let isPermanent = !this.time || this.time == 0;
let isPermanent = !this.time || this.time === 0;
try {
let res = null;
let query = {
url: this.url,
password: this.password,
custom: this.custom,
customLink: this.customLink,
};
if (isPermanent) {
res = await api.create(this.url, this.password);
} else {
res = await api.create(this.url, this.password, this.time, this.unit);
if (this.custom) {
if (!this.checkCustomLink()) {
alert("自定义链接,只支持英文和数字");
return;
}
}
if (!isPermanent) {
Object.assign(query, {
expires: this.time,
unit: this.unit,
});
}
const res = await api.create(query);
this.links.push(res);
this.sort();
@ -196,6 +242,18 @@ export default {
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) {
event.preventDefault();
try {
@ -232,3 +290,16 @@ export default {
},
};
</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": "نطاق",
"settingsUpdated": "تم تعديل الإعدادات",
"shareDuration": "",
"shareCustomLink": "عرف الرابط",
"shareManagement": "",
"singleClick": "",
"themes": {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -90,13 +90,19 @@ var sharePostHandler = withPermShare(func(w http.ResponseWriter, r *http.Request
defer r.Body.Close()
}
bytes := make([]byte, 6) //nolint:gomnd
_, err := rand.Read(bytes)
if err != nil {
return http.StatusInternalServerError, err
str := ""
if body.Custom {
str = body.CustomLink
} 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

View File

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