forked from GitHubMirrors/silverbullet-icalendar
Robust fetch with User-Agent and URL encoding
Some checks failed
Build SilverBullet Plug / build (push) Failing after 26s
Some checks failed
Build SilverBullet Plug / build (push) Failing after 26s
This commit is contained in:
7
.github/workflows/publish.yml
vendored
7
.github/workflows/publish.yml
vendored
@@ -22,7 +22,6 @@ jobs:
|
|||||||
|
|
||||||
- name: Build Plug
|
- name: Build Plug
|
||||||
run: |
|
run: |
|
||||||
deno --version
|
|
||||||
deno task build -- --no-check
|
deno task build -- --no-check
|
||||||
ls -lh *.plug.js
|
ls -lh *.plug.js
|
||||||
|
|
||||||
@@ -30,18 +29,16 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
git config --local user.email "action@github.com"
|
git config --local user.email "action@github.com"
|
||||||
git config --local user.name "GitHub Action"
|
git config --local user.name "GitHub Action"
|
||||||
git status
|
|
||||||
git branch -a
|
|
||||||
git add icalendar.plug.js
|
git add icalendar.plug.js
|
||||||
if git diff --quiet --staged; then
|
if git diff --quiet --staged; then
|
||||||
echo "No changes to commit"
|
echo "No changes to commit"
|
||||||
else
|
else
|
||||||
git commit -m "Build and update icalendar.plug.js [skip ci]"
|
git commit -m "Build and update icalendar.plug.js [skip ci]"
|
||||||
git push --force
|
git push
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Upload Build Artifact
|
- name: Upload Build Artifact
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: icalendar-plug
|
name: icalendar-plug
|
||||||
path: "*.plug.js"
|
path: "*.plug.js"
|
||||||
|
|||||||
28
icalendar.ts
28
icalendar.ts
@@ -154,14 +154,32 @@ async function getSources(): Promise<Source[]> {
|
|||||||
* Fetches and parses events from a single calendar source
|
* Fetches and parses events from a single calendar source
|
||||||
*/
|
*/
|
||||||
async function fetchAndParseCalendar(source: Source): Promise<CalendarEvent[]> {
|
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}`);
|
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) {
|
if (!response.ok) {
|
||||||
const error = new Error(`HTTP ${response.status}: ${response.statusText}`);
|
const body = await response.text();
|
||||||
console.error(`[iCalendar] HTTP error:`, { source, status: response.status, statusText: response.statusText });
|
const errorDetail = body.slice(0, 200).replace(/\n/g, " ");
|
||||||
throw error;
|
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();
|
const icsData = await response.text();
|
||||||
|
|||||||
Reference in New Issue
Block a user