Skip to content

Commit ef35c89

Browse files
committed
feat: added url shortener service
1 parent a0bb91b commit ef35c89

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/main.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,37 @@ if (typeof Yasgui !== "undefined") {
8484
},
8585

8686
yasqe: {
87+
createShortLink: async (yasqe, longUrl) => {
88+
const YOURLS_API_URL = 'https://shorter.matdata.eu/api.php';
89+
90+
try {
91+
const params = new URLSearchParams({
92+
action: 'shorturl',
93+
url: longUrl,
94+
format: 'json',
95+
});
96+
97+
const response = await fetch(`${YOURLS_API_URL}?${params.toString()}`, {
98+
method: 'GET'
99+
});
100+
101+
if (!response.ok) {
102+
throw new Error(`HTTP error! status: ${response.status}`);
103+
}
104+
105+
const data = await response.json();
106+
107+
if (data.status === 'fail') {
108+
throw new Error(data.message || 'Failed to shorten URL');
109+
}
110+
111+
return data.shorturl;
112+
113+
} catch (error) {
114+
console.error('YOURLS shortening error:', error);
115+
throw error;
116+
}
117+
},
87118
snippets: [
88119
{ label: "SELECT", code: "SELECT * WHERE {\n ?s ?p ?o .\n} LIMIT 10", group: "QUERY" },
89120
{ label: "CONSTRUCT", code: "CONSTRUCT {\n ?s ?p ?o .\n} WHERE {\n ?s ?p ?o .\n} LIMIT 10", group: "QUERY" },

0 commit comments

Comments
 (0)