Browse Source

Add setting about expire days

master
Pin Lin 2 months ago
parent
commit
8792467660
Signed by: PinLin <moneycat711@gmail.com> GPG Key ID: AA25245559047A94
2 changed files with 20 additions and 9 deletions
  1. +8
    -4
      index.html
  2. +12
    -5
      js/main.js

+ 8
- 4
index.html View File

@@ -20,16 +20,20 @@
<div id="urlBox">
<div class="urls container">
<div class="url row">
<h3 class="text-center col-6">自訂名稱 Alias</h3>
<h3 class="text-center col-6">目標網址 Target</h3>
<h3 class="text-center col-4">自訂名稱 Alias</h3>
<h3 class="text-center col-4">目標網址 Target</h3>
<h3 class="text-center col-4">有效天數 Days</h3>
</div>
<!--url list-->
</div>
<div class="urlAdder container">
<div class="url row">
<input class="name text-center col-6" name="name" type="text" placeholder="留白將隨機產生">
<input class="target text-center col-6" name="target" type="text" placeholder="填入目標長網址">
<input class="text-center col-4 name" name="name" type="text" placeholder="留白將隨機產生">
<input class="text-center col-4 target" name="target" type="text" placeholder="填入目標長網址">
<input class="text-center col-4 expire-days" name="expire-days" type="number" placeholder="留白為無期限">

<p class="col-12"></p>

<p class="col-sm-2"></p>
<a class="btn btn-primary col-sm-8 col-12" href="javascript:" onclick="createUrl()">縮網址 Shorten</a>
<p class="col-sm-2"></p>


+ 12
- 5
js/main.js View File

@@ -11,8 +11,9 @@ const addRowToView = (url) => {
const newUrlRow = (data) => {
return $(`
<div class="url row">
<a class="text-center col-6" href="${backend}/${data.name}" target="_blank">${backend}/${data.name}</a>
<a class="text-center col-6" href="${data.target}" target="_blank">${data.target}</a>
<a class="text-center col-4" href="${backend}/${data.name}" target="_blank">${backend}/${data.name}</a>
<a class="text-center col-4" href="${data.target}" target="_blank">${data.target}</a>
<p class="text-center col-4">${data.expireTime}</p>
</div>
`)
}
@@ -20,13 +21,19 @@ const newUrlRow = (data) => {
const createUrl = async () => {
let name = $('#urlBox .name')[0].value || null
let target = $('#urlBox .target')[0].value
let expireDays = $('#urlBox .expire-days')[0].value || null

if (!target) {
alert("請輸入目標網址")
return
}

postUrls(name, target)
let expireSeconds = null
if (expireDays) {
expireSeconds = 60 * 60 * 24 * expireDays
}

postUrls(name, target, expireSeconds)
.done((res) => {
console.log(res)
addRowToView(res.result)
@@ -43,13 +50,13 @@ const createUrl = async () => {
})
}

const postUrls = (name, target) => {
const postUrls = (name, target, expireSeconds) => {
return $.ajax({
type: 'POST',
dataType: 'json',
url: `${backend}/api/urls`,
data: JSON.stringify({
name, target
name, target, expireSeconds
}),
processData: false,
contentType: 'application/json; charset=UTF-8'


Loading…
Cancel
Save