-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
27 lines (23 loc) · 681 Bytes
/
Copy pathutils.js
File metadata and controls
27 lines (23 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const axios = require("axios");
module.exports = {
/**
* Shortens a URL using is.gd API.
* @param {string} longUrl - The full URL to shorten.
* @returns {Promise<string|null>} Shortened URL or null if failed.
*/
shortenURL: async function (longUrl) {
if (!longUrl || typeof longUrl !== "string") return null;
try {
const response = await axios.get("https://is.gd/create.php", {
params: { format: "simple", url: longUrl },
timeout: 3000,
});
if (response.status === 200 && typeof response.data === "string") {
return response.data.trim();
}
return null;
} catch {
return null;
}
}
};