Skip to content

Commit

Permalink
fix: resolved this.app passing with type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
sundevista committed Jan 11, 2024
1 parent 3ad514b commit 6d6cfc6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/apis/youtube.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { App, requestUrl } from 'obsidian';
import { App, TFolder, requestUrl } from 'obsidian';
import { filterStringData, parseChapters, parseISODuration, parseVideoId } from 'src/utils/parser';
import { YouTubeTemplatePluginSettings } from '../settings';
import { VideoData } from '../types/video-data';
Expand Down Expand Up @@ -75,8 +75,9 @@ export async function downloadVideoThumbnail(app: App, imageUrl: string): Promis
const response = await requestUrl(imageUrl);

const filename = `${new Date().getTime()}.${imageUrl.split('.').pop()}`;
const abstractFile = this.app.vault.getAbstractFileByPath(app.vault.getConfig('attachmentFolderPath'));

if (!this.app.vault.getAbstractFileByPath(app.vault.getConfig('attachmentFolderPath'))) {
if (!(abstractFile instanceof TFolder)) {
throw new Error(`Attachment folder '${app.vault.getConfig('attachmentFolderPath')}' does not exist`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/modals/insert-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export class InsertTemplateModal extends Modal {
const filepath = normalizePath(`${this.plugin.settings.folder}/${filterFilename(data.title)}.md`);

// Check if the file already exists
if (findTFile(filepath)) {
if (findTFile(filepath, this.app)) {
new Notice(`File ${filepath} already exists`);
} else {
await this.app.vault.create(filepath, processTemplate(data, this.plugin.settings));

const abstractFile = findTFile(filepath);
const abstractFile = findTFile(filepath, this.app);
if (abstractFile) {
this.app.workspace.getLeaf().openFile(abstractFile);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TAbstractFile, TFile, TFolder } from 'obsidian';
import { App, TAbstractFile, TFile, TFolder } from 'obsidian';

export function findTFile(filepath: string): TFile | null {
const abstractFile = this.app.vault.getAbstractFileByPath(filepath);
export function findTFile(filepath: string, app: App): TFile | null {
const abstractFile = app.vault.getAbstractFileByPath(filepath);

return abstractFile instanceof TFile ? abstractFile : null;
}
Expand Down

0 comments on commit 6d6cfc6

Please sign in to comment.