Skip to content

Commit

Permalink
fix: use isLegalUrl for suggestUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
SharzyL committed Apr 13, 2024
1 parent b87e59d commit 4415c63
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/handlers/handleWrite.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { verifyAuth } from "../auth.js"
import { getBoundary, parseFormdata } from "../parseFormdata.js"
import { decode, genRandStr, getDispFilename, params, parseExpiration, parsePath, WorkerError } from "../common.js"
import {
decode,
genRandStr,
getDispFilename,
isLegalUrl,
params,
parseExpiration,
parsePath,
WorkerError,
} from "../common.js"

async function createPaste(env, content, isPrivate, expire, short, createDate, passwd, filename) {
const now = new Date().toISOString()
Expand Down Expand Up @@ -37,18 +46,9 @@ async function createPaste(env, content, isPrivate, expire, short, createDate, p
}

function suggestUrl(content, filename, short, baseUrl) {
function isUrl(text) {
try {
new URL(text)
return true
} catch (e) {
return false
}
}

if (filename) {
return `${baseUrl}/${short}/${filename}`
} else if (isUrl(decode(content))) {
} else if (isLegalUrl(decode(content))) {
return `${baseUrl}/u/${short}`
} else {
return null
Expand Down

0 comments on commit 4415c63

Please sign in to comment.