Skip to content

Commit f779ce9

Browse files
committed
Bump version to 2.3.3 and restore Basic Auth support
Fixes #4
1 parent 5e359bf commit f779ce9

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Send to ntfy",
4-
"version": "2.3.2",
4+
"version": "2.3.3",
55
"description": "Send notifications to ntfy.sh with file attachments, priority, and tags",
66
"permissions": [
77
"activeTab",

ntfy.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,24 @@ const NtfyAPI = {
2323
* @param {string} accessToken - Bearer token for authentication
2424
* @returns {Headers}
2525
*/
26-
buildAuthHeaders(accessToken) {
26+
buildAuthHeaders(accessToken, apiUrl) {
2727
const headers = new Headers();
2828
if (accessToken) {
2929
headers.set('Authorization', `Bearer ${accessToken}`);
30+
} else if (apiUrl) {
31+
try {
32+
const url = new URL(apiUrl);
33+
if (url.username || url.password) {
34+
const username = decodeURIComponent(url.username);
35+
const password = decodeURIComponent(url.password);
36+
const credentials = `${username}:${password}`;
37+
// Use robust base64 encoding that supports UTF-8
38+
const auth = btoa(unescape(encodeURIComponent(credentials)));
39+
headers.set('Authorization', `Basic ${auth}`);
40+
}
41+
} catch (e) {
42+
// Invoke error handling or logging if necessary, but silent failure relies on no auth
43+
}
3044
}
3145
return headers;
3246
},
@@ -83,7 +97,7 @@ const NtfyAPI = {
8397
*/
8498
async sendNotification(config, topic, { message, title, priority, tags }) {
8599
const fullUrl = this.buildTopicUrl(config.apiUrl, topic);
86-
const headers = this.buildAuthHeaders(config.accessToken);
100+
const headers = this.buildAuthHeaders(config.accessToken, config.apiUrl);
87101

88102
if (title) {
89103
headers.set('X-Title', this.encodeHeaderValue(title));
@@ -123,7 +137,7 @@ const NtfyAPI = {
123137
*/
124138
async sendAttachment(config, topic, { data, filename, message, title, priority, tags }) {
125139
const fullUrl = this.buildTopicUrl(config.apiUrl, topic);
126-
const headers = this.buildAuthHeaders(config.accessToken);
140+
const headers = this.buildAuthHeaders(config.accessToken, config.apiUrl);
127141

128142
headers.set('X-Filename', this.encodeHeaderValue(filename));
129143

0 commit comments

Comments
 (0)