#777 - Extra states for invalid files

This commit is contained in:
Elio Struyf
2024-03-19 12:34:00 +01:00
parent 3842777f71
commit d2b9307a65
2 changed files with 11 additions and 5 deletions
+6 -4
View File
@@ -741,15 +741,17 @@ export class ArticleHelper {
* Get the details of the current article
* @returns
*/
public static async getDetails(filePath: string) {
public static async getDetails(
filePath: string
): Promise<Article | 'nofilepath' | 'nodata' | 'notsupported'> {
const baseUrl = Settings.get<string>(SETTING_SITE_BASEURL);
if (!filePath) {
return null;
return 'nofilepath';
}
const document = await workspace.openTextDocument(filePath);
if (!ArticleHelper.isSupportedFile(document)) {
return null;
return 'notsupported';
}
const article = await ArticleHelper.getFrontMatterByPath(filePath);
@@ -805,7 +807,7 @@ export class ArticleHelper {
};
}
return null;
return 'nodata';
}
/**
+5 -1
View File
@@ -199,7 +199,7 @@ export class DataListener extends BaseListener {
if (filePath) {
articleDetails = await ArticleHelper.getDetails(filePath);
if (!articleDetails) {
if (!articleDetails || articleDetails === 'nodata') {
try {
const contents = await ArticleHelper.getContents(filePath);
if (contents) {
@@ -214,6 +214,10 @@ export class DataListener extends BaseListener {
});
return;
}
} else if (articleDetails === 'notsupported' || articleDetails === 'nofilepath') {
// No file or invalid file format
this.sendMsg(Command.metadata, undefined);
return;
}
} else {
this.sendMsg(Command.metadata, undefined);