Skip to content

Commit

Permalink
Fix plugin on ipad by removing node-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
aladmit committed Jul 23, 2022
1 parent 1a963cc commit 3db677c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2,082 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ You can make a [pull request](https://github.com/elias-sundqvist/obsidian-annota

## Changelog

### 0.2.4 (2022-07-23)
* Fix [plugin fails to start on iPad](https://github.com/elias-sundqvist/obsidian-annotator/issues/176)

### 0.2.2 (2022-05-14) *Minor improvement*
* hypothes.is updated up to v1.1055.0

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "obsidian-annotator",
"name": "Annotator",
"version": "0.2.2",
"minAppVersion": "0.13.19",
"minAppVersion": "0.13.25",
"description": "This is a sample plugin for Obsidian. It allows you to open and annotate PDF and EPUB files.",
"author": "Obsidian",
"authorUrl": "https://obsidian.md/about",
Expand Down
88 changes: 0 additions & 88 deletions src/corsFetch.tsx

This file was deleted.

12 changes: 6 additions & 6 deletions src/defineGenericAnnotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SAMPLE_PDF_URL, SAMPLE_EPUB_URL } from './constants';
import { OfflineIframe } from 'react-offline-iframe';
import React, { useEffect } from 'react';
import { SpecificAnnotationProps } from 'types';
import { b64_to_utf8, utf8_to_b64, wait } from 'utils';
import { fetchUrl, b64_to_utf8, utf8_to_b64, wait } from 'utils';
import { deleteAnnotation, loadAnnotations, writeAnnotation } from 'annotationFileUtils';
import { Annotation } from './types';
import AnnotatorPlugin from 'main';
Expand All @@ -13,7 +13,6 @@ import { getSubtitles } from 'youtube-captions-scraper';
import getYouTubeMetaData from 'youtube-metadata-scraper';
import { deleteVideoAnnotation, loadVideoAnnotations, writeVideoAnnotation } from 'videoAnnotationFileUtils';
import { awaitResourceLoading, resourcesZip, resourceUrls } from 'resourcesFolder';
import { corsFetch } from 'corsFetch';

const urlToPathMap = new Map();
const proxiedHosts = new Set(['cdn.hypothes.is', 'via.hypothes.is', 'hypothes.is', 'annotate.tv']);
Expand Down Expand Up @@ -81,10 +80,10 @@ export default ({ vault, plugin }) => {
});
}
if (href.startsWith(`https://annotate.tv/api/transcript`) && 'video' in props) {
const video_metadata = await getYouTubeMetaData(corsFetch, props.video);
const video_metadata = await getYouTubeMetaData(fetchUrl, props.video);
const video_id = video_metadata.shortlinkUrl.substr('https://youtu.be/'.length);
res = (
await getSubtitles(corsFetch, {
await getSubtitles(fetchUrl, {
videoID: video_id, // youtube video id
lang: 'en' // default: `en`
})
Expand Down Expand Up @@ -149,7 +148,7 @@ export default ({ vault, plugin }) => {
};
}
if (href == `https://annotate.tv/videos/620d5a42b9ab630009bf3e31.html` && 'video' in props) {
const video_metadata = await getYouTubeMetaData(corsFetch, props.video);
const video_metadata = await getYouTubeMetaData(fetchUrl, props.video);
const video_id = video_metadata.shortlinkUrl.substr('https://youtu.be/'.length);
const video_data = {
props: {
Expand Down Expand Up @@ -332,7 +331,8 @@ export default ({ vault, plugin }) => {
return new Response(null, { status: 404, statusText: 'file not found' });
}
}
return await corsFetch(requestInfo, requestInit);

return await fetchUrl(requestInfo, requestInit);
}}
htmlPostProcessFunction={(html: string) => {
if ('pdf' in props) {
Expand Down
5 changes: 2 additions & 3 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import { PdfAnnotationProps, EpubAnnotationProps, VideoAnnotationProps, WebAnnot
import { EditorState } from '@codemirror/state';
import AnnotatorSettingsTab, { AnnotatorSettings, DEFAULT_SETTINGS, IHasAnnotatorSettings } from 'settings';
import AnnotatorView from 'annotatorView';
import { wait } from 'utils';
import { fetchUrl, wait } from 'utils';
import defineWebAnnotation from 'defineWebAnnotation';
import { awaitResourceLoading, loadResourcesZip, unloadResources } from 'resourcesFolder';
import stringEncodedResourcesFolder from './resources!zipStringEncoded';
import * as jszip from 'jszip';
import { corsFetch } from './corsFetch';

export default class AnnotatorPlugin extends Plugin implements IHasAnnotatorSettings {
settings: AnnotatorSettings;
Expand All @@ -53,7 +52,7 @@ export default class AnnotatorPlugin extends Plugin implements IHasAnnotatorSett
await loadResourcesZip(jszip.loadAsync(stringEncodedResourcesFolder));
if (this.settings.annotateTvUrl) {
try {
const response = await corsFetch(this.settings.annotateTvUrl);
const response = await fetchUrl(this.settings.annotateTvUrl);
if (response.ok) {
await loadResourcesZip(jszip.loadAsync(await response.arrayBuffer()));
} else {
Expand Down
Loading

0 comments on commit 3db677c

Please sign in to comment.