Skip to content

Commit 3db677c

Browse files
committed
Fix plugin on ipad by removing node-fetch
1 parent 1a963cc commit 3db677c

File tree

7 files changed

+37
-2082
lines changed

7 files changed

+37
-2082
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ You can make a [pull request](https://github.com/elias-sundqvist/obsidian-annota
6969

7070
## Changelog
7171

72+
### 0.2.4 (2022-07-23)
73+
* Fix [plugin fails to start on iPad](https://github.com/elias-sundqvist/obsidian-annotator/issues/176)
74+
7275
### 0.2.2 (2022-05-14) *Minor improvement*
7376
* hypothes.is updated up to v1.1055.0
7477

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "obsidian-annotator",
33
"name": "Annotator",
44
"version": "0.2.2",
5-
"minAppVersion": "0.13.19",
5+
"minAppVersion": "0.13.25",
66
"description": "This is a sample plugin for Obsidian. It allows you to open and annotate PDF and EPUB files.",
77
"author": "Obsidian",
88
"authorUrl": "https://obsidian.md/about",

src/corsFetch.tsx

Lines changed: 0 additions & 88 deletions
This file was deleted.

src/defineGenericAnnotation.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SAMPLE_PDF_URL, SAMPLE_EPUB_URL } from './constants';
22
import { OfflineIframe } from 'react-offline-iframe';
33
import React, { useEffect } from 'react';
44
import { SpecificAnnotationProps } from 'types';
5-
import { b64_to_utf8, utf8_to_b64, wait } from 'utils';
5+
import { fetchUrl, b64_to_utf8, utf8_to_b64, wait } from 'utils';
66
import { deleteAnnotation, loadAnnotations, writeAnnotation } from 'annotationFileUtils';
77
import { Annotation } from './types';
88
import AnnotatorPlugin from 'main';
@@ -13,7 +13,6 @@ import { getSubtitles } from 'youtube-captions-scraper';
1313
import getYouTubeMetaData from 'youtube-metadata-scraper';
1414
import { deleteVideoAnnotation, loadVideoAnnotations, writeVideoAnnotation } from 'videoAnnotationFileUtils';
1515
import { awaitResourceLoading, resourcesZip, resourceUrls } from 'resourcesFolder';
16-
import { corsFetch } from 'corsFetch';
1716

1817
const urlToPathMap = new Map();
1918
const proxiedHosts = new Set(['cdn.hypothes.is', 'via.hypothes.is', 'hypothes.is', 'annotate.tv']);
@@ -81,10 +80,10 @@ export default ({ vault, plugin }) => {
8180
});
8281
}
8382
if (href.startsWith(`https://annotate.tv/api/transcript`) && 'video' in props) {
84-
const video_metadata = await getYouTubeMetaData(corsFetch, props.video);
83+
const video_metadata = await getYouTubeMetaData(fetchUrl, props.video);
8584
const video_id = video_metadata.shortlinkUrl.substr('https://youtu.be/'.length);
8685
res = (
87-
await getSubtitles(corsFetch, {
86+
await getSubtitles(fetchUrl, {
8887
videoID: video_id, // youtube video id
8988
lang: 'en' // default: `en`
9089
})
@@ -149,7 +148,7 @@ export default ({ vault, plugin }) => {
149148
};
150149
}
151150
if (href == `https://annotate.tv/videos/620d5a42b9ab630009bf3e31.html` && 'video' in props) {
152-
const video_metadata = await getYouTubeMetaData(corsFetch, props.video);
151+
const video_metadata = await getYouTubeMetaData(fetchUrl, props.video);
153152
const video_id = video_metadata.shortlinkUrl.substr('https://youtu.be/'.length);
154153
const video_data = {
155154
props: {
@@ -332,7 +331,8 @@ export default ({ vault, plugin }) => {
332331
return new Response(null, { status: 404, statusText: 'file not found' });
333332
}
334333
}
335-
return await corsFetch(requestInfo, requestInit);
334+
335+
return await fetchUrl(requestInfo, requestInit);
336336
}}
337337
htmlPostProcessFunction={(html: string) => {
338338
if ('pdf' in props) {

src/main.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ import { PdfAnnotationProps, EpubAnnotationProps, VideoAnnotationProps, WebAnnot
2323
import { EditorState } from '@codemirror/state';
2424
import AnnotatorSettingsTab, { AnnotatorSettings, DEFAULT_SETTINGS, IHasAnnotatorSettings } from 'settings';
2525
import AnnotatorView from 'annotatorView';
26-
import { wait } from 'utils';
26+
import { fetchUrl, wait } from 'utils';
2727
import defineWebAnnotation from 'defineWebAnnotation';
2828
import { awaitResourceLoading, loadResourcesZip, unloadResources } from 'resourcesFolder';
2929
import stringEncodedResourcesFolder from './resources!zipStringEncoded';
3030
import * as jszip from 'jszip';
31-
import { corsFetch } from './corsFetch';
3231

3332
export default class AnnotatorPlugin extends Plugin implements IHasAnnotatorSettings {
3433
settings: AnnotatorSettings;
@@ -53,7 +52,7 @@ export default class AnnotatorPlugin extends Plugin implements IHasAnnotatorSett
5352
await loadResourcesZip(jszip.loadAsync(stringEncodedResourcesFolder));
5453
if (this.settings.annotateTvUrl) {
5554
try {
56-
const response = await corsFetch(this.settings.annotateTvUrl);
55+
const response = await fetchUrl(this.settings.annotateTvUrl);
5756
if (response.ok) {
5857
await loadResourcesZip(jszip.loadAsync(await response.arrayBuffer()));
5958
} else {

0 commit comments

Comments
 (0)