Robust fetch with User-Agent and URL encoding
Some checks failed
Build SilverBullet Plug / build (push) Failing after 26s

This commit is contained in:
2026-02-16 07:48:32 -08:00
parent af12466721
commit 3fa0bd553b
2 changed files with 25 additions and 10 deletions

View File

@@ -22,7 +22,6 @@ jobs:
- name: Build Plug
run: |
deno --version
deno task build -- --no-check
ls -lh *.plug.js
@@ -30,18 +29,16 @@ jobs:
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git status
git branch -a
git add icalendar.plug.js
if git diff --quiet --staged; then
echo "No changes to commit"
else
git commit -m "Build and update icalendar.plug.js [skip ci]"
git push --force
git push
fi
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: icalendar-plug
path: "*.plug.js"
path: "*.plug.js"

View File

@@ -154,14 +154,32 @@ async function getSources(): Promise<Source[]> {
* Fetches and parses events from a single calendar source
*/
async function fetchAndParseCalendar(source: Source): Promise<CalendarEvent[]> {
const url = source.url.trim();
let url = source.url.trim();
// Handle internal spaces which are common in copy-pasted URLs
if (url.includes(" ")) {
console.log(`[iCalendar] URL contains spaces, encoding: "${url}"`);
url = encodeURI(url);
}
console.log(`[iCalendar] Fetching: ${url}`);
const response = await fetch(url);
const response = await fetch(url, {
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
});
if (!response.ok) {
const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
console.error(`[iCalendar] HTTP error:`, { source, status: response.status, statusText: response.statusText });
throw error;
const body = await response.text();
const errorDetail = body.slice(0, 200).replace(/\n/g, " ");
console.error(`[iCalendar] HTTP ${response.status} Error:`, {
url,
status: response.status,
statusText: response.statusText,
bodyPreview: errorDetail
});
throw new Error(`HTTP ${response.status}: ${response.statusText || 'Error'} - ${errorDetail}`);
}
const icsData = await response.text();