Skip to content

Commit d38cb0a

Browse files
committed
feat: add URL decoding tool component
1 parent deadbb0 commit d38cb0a

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<template>
2+
<NForm label-placement="top">
3+
<!-- Input Section -->
4+
<NFormItem :label="t.encodedInput">
5+
<NInput
6+
v-model:value="inputText"
7+
type="textarea"
8+
:placeholder="t.inputPlaceholder"
9+
clearable
10+
>
11+
</NInput>
12+
</NFormItem>
13+
14+
<!-- Action Button -->
15+
<NFormItem :label="t.action">
16+
<NFlex align="center">
17+
<NButton type="primary" @click="decodeURL" :disabled="!inputText">
18+
{{ t.decodeButton }}
19+
</NButton>
20+
<NCheckbox v-model:checked="deep">
21+
{{ t.deepLabel }}
22+
</NCheckbox>
23+
</NFlex>
24+
</NFormItem>
25+
26+
<!-- Output Section -->
27+
<NFormItem :label="t.decodedOutput">
28+
<NInput
29+
ref="outputTextArea"
30+
v-model:value="outputText"
31+
type="textarea"
32+
:placeholder="t.outputPlaceholder"
33+
readonly
34+
>
35+
</NInput>
36+
</NFormItem>
37+
</NForm>
38+
</template>
39+
40+
<script setup lang="ts">
41+
import { ref, computed } from "vue"
42+
import { useMessage } from "naive-ui"
43+
import { NFlex, NForm, NFormItem, NInput, NButton, NCheckbox } from "naive-ui"
44+
45+
const message = useMessage()
46+
const inputText = ref("")
47+
const outputText = ref("")
48+
const deep = ref(true)
49+
50+
// i18n
51+
const isZh = computed(() => window.location.pathname.startsWith("/zh/"))
52+
const t = computed(() => isZh.value ? i18n.zh : i18n.en)
53+
const i18n = {
54+
en: {
55+
encodedInput: 'Encoded Input',
56+
action: 'Action',
57+
decodedOutput: 'Decoded Output',
58+
inputPlaceholder: 'Please enter the URL encoded string',
59+
decodeButton: 'Decode',
60+
deepLabel: 'Deep',
61+
outputPlaceholder: 'Decoded result will appear here',
62+
decodeError: 'Decoding failed. Please check if the input is properly URL encoded.'
63+
},
64+
zh: {
65+
encodedInput: '编码输入',
66+
action: '操作',
67+
decodedOutput: '解码输出',
68+
inputPlaceholder: '请输入URL编码的字符串',
69+
decodeButton: '解码',
70+
deepLabel: '深度解码',
71+
outputPlaceholder: '解码结果将显示在此处',
72+
decodeError: '解码失败,请检查输入是否正确编码。'
73+
}
74+
}
75+
76+
// URL Decoding
77+
const deepDecode = (encodedStr: string, recursive: boolean) => {
78+
let decoded = decodeURIComponent(encodedStr)
79+
80+
if (!recursive) return decoded
81+
82+
let hasChanged: boolean
83+
do {
84+
hasChanged = false
85+
try {
86+
const next = decodeURIComponent(decoded)
87+
if (next !== decoded) {
88+
decoded = next
89+
hasChanged = true
90+
}
91+
} catch {
92+
break
93+
}
94+
} while (hasChanged)
95+
96+
return decoded
97+
}
98+
99+
const decodeURL = () => {
100+
outputText.value = ""
101+
if (!inputText.value.trim()) {
102+
return
103+
}
104+
try {
105+
outputText.value = deepDecode(inputText.value, deep.value)
106+
} catch (error) {
107+
message.error(t.value.decodeError)
108+
outputText.value = ""
109+
}
110+
}
111+
</script>

docs/.vuepress/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,6 @@ export default defineUserConfig({
151151
"./components/dropbox/Callback.vue"
152152
),
153153
"@115/Token": path.resolve(__dirname, "./components/115/Token.vue"),
154+
"@Toolkit/URLDecode": path.resolve(__dirname, "./components/toolkit/URLDecode.vue"),
154155
},
155156
});

docs/guide/drivers/cloudreve.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ Only the string following cloudreve-session= is required.
4343

4444
Default is `/`, which can be obtained from the `?path=` in the web link.
4545

46+
You can get the parameter decoded here:
47+
48+
<NaiveClient>
49+
<URLDecode />
50+
</NaiveClient>
51+
52+
<script setup lang="ts">
53+
import URLDecode from "@Toolkit/URLDecode";
54+
</script>
55+
4656
### Enable Folder Size
4757

4858
Enable Cloudreve V3 server to calculate the size of each folder and generate thumbnails for each file. Enabling this feature may cause server errors or slow performance, and it is `disabled` by default.

docs/guide/drivers/cloudreve_v4.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ You may need to log in anew to see this request.
5959

6060
Cloudreve V4 uses a custom URI as the path, which can be obtained from the `?path=` in the web link.
6161

62+
You can get the parameter decoded here:
63+
64+
<NaiveClient>
65+
<URLDecode />
66+
</NaiveClient>
67+
68+
<script setup lang="ts">
69+
import URLDecode from "@Toolkit/URLDecode";
70+
</script>
71+
6272
#### Mounting My Files
6373

6474
Default is `cloudreve://my/`, listing user files.

docs/zh/guide/drivers/cloudreve.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ Cookie 获取方法:
4141

4242
默认为:`/`,可从网页链接的 `?path=` 中获取。
4343

44+
您可以在此处对获取到的被编码参数进行解码:
45+
46+
<NaiveClient>
47+
<URLDecode />
48+
</NaiveClient>
49+
50+
<script setup lang="ts">
51+
import URLDecode from "@Toolkit/URLDecode";
52+
</script>
53+
4454
### 启用缩略图和文件夹大小
4555

4656
让 Cloudreve V3 服务端统计每个文件夹的大小并为每个文件生成略缩图,启用可能会造成服务端报错、运行缓慢,默认禁用。

docs/zh/guide/drivers/cloudreve_v4.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ Token 获取方法:
6060

6161
Cloudreve V4 采用自定义 URI 作为路径。可从网页链接的 `?path=` 中获取。
6262

63+
您可以在此处对获取到的被编码参数进行解码:
64+
65+
<NaiveClient>
66+
<URLDecode />
67+
</NaiveClient>
68+
69+
<script setup lang="ts">
70+
import URLDecode from "@Toolkit/URLDecode";
71+
</script>
72+
6373
#### 挂载「我的文件」
6474

6575
默认为 `cloudreve://my/`,列出用户文件。

0 commit comments

Comments
 (0)