Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
haouarihk committed Jan 10, 2024
1 parent 7a2b24a commit b332f03
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 32 deletions.
23 changes: 13 additions & 10 deletions src/extractors/audio-extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import debug from "debug";
const logger = debug("textgenerator:Extractor:AudioExtractor");

import { WhisperProviderName } from "../ui/settings/sections/otherProviders/whisper";

export const supportedAudioExtensions = [
"mp3",
"mp4",
"mpeg",
"mpga",
"m4a",
"wav",
"webm",
"ogg"
];

export default class AudioExtractor extends Extractor {
constructor(app: App, plugin: TextGeneratorPlugin) {
super(app, plugin);
Expand All @@ -31,16 +43,7 @@ export default class AudioExtractor extends Extractor {
}

async extract(filePath: string) {
const supportedAudioExtensions = [
"mp3",
"mp4",
"mpeg",
"mpga",
"m4a",
"wav",
"webm",
"ogg"
];

const embeds = this.app.metadataCache
.getCache(filePath)
?.embeds?.filter((embed) =>
Expand Down
12 changes: 4 additions & 8 deletions src/extractors/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ContentExtractor } from "./content-extractor";
import TextGeneratorPlugin from "#/main";
import { supportedAudioExtensions } from "./audio-extractor";

export default async function read(path: string, plugin: TextGeneratorPlugin, otherOptions?: any) {
if (!app.vault.adapter.exists(path)) throw "file doesn't exist";
Expand All @@ -8,6 +9,9 @@ export default async function read(path: string, plugin: TextGeneratorPlugin, ot

const extractor = new ContentExtractor(plugin.app, plugin);

if (supportedAudioExtensions.includes(extension?.toLowerCase()))
extractor.setExtractor("AudioExtractor")

switch (extension) {
// pdf
case "pdf":
Expand All @@ -22,14 +26,6 @@ export default async function read(path: string, plugin: TextGeneratorPlugin, ot
extractor.setExtractor("ImageExtractor")
break;

// audio
case "mp3":
extractor.setExtractor("AudioExtractor")
break;
case "webm":
extractor.setExtractor("AudioExtractor")
break;

default:
const p = self.app.vault.getAbstractFileByPath(path);
if (!p) throw new Error("file doesn't exist");
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ export default class TextGeneratorPlugin extends Plugin {
if (testFiles.length === 0) {
let retryTimes = 30;
const timer = setInterval(() => {
console.log("attempting to get files", retryTimes)
testFiles = app.vault.getFiles();
retryTimes--;

Expand Down
9 changes: 5 additions & 4 deletions src/scope/versionManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import set from "lodash.set";
import pkg from "../../package.json";
import TextGeneratorPlugin from "../main";
import { Version } from "../types";
export default class VersionManager {
Expand All @@ -11,11 +10,13 @@ export default class VersionManager {
}

async load() {
const version = this.plugin.manifest.version;

// check if the version compatible with the format
if (!/\d+\.\d+\.\d+(-beta)?/.test(pkg.version))
return console.warn("version", pkg.version, "is not valid");
if (!/\d+\.\d+\.\d+(-beta)?/.test(version))
return console.warn("version", version, "is not valid");

this.currentVersion = pkg.version as Version;
this.currentVersion = version as Version;

if (!this.isOldVersion(this.plugin.settings.version)) return;

Expand Down
17 changes: 10 additions & 7 deletions src/services/text-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,15 @@ ${removeYAML(content)}
(f) => f.path.startsWith(promptsPath) && !f.path.includes("/trash/")
);
return paths.map((s) => {
return {
title: s.path.substring(promptsPath.length + 1),
ctime: s.stat.ctime,
path: s.path,
...this.getMetadata(s.path),
};
const conf = this.getMetadata(s.path) as {
title: string,
ctime: number,
path: string
} & ReturnType<typeof this.getMetadata>
conf.title = s.path.substring(promptsPath.length + 1);
conf.ctime = s.stat.ctime
conf.path = s.path
return conf;
});
}

Expand Down Expand Up @@ -860,10 +863,10 @@ ${removeYAML(content)}
}

async updateTemplatesCache() {
// get files, it will be empty onLoad, that's why we are using the getFilesOnLoad function
const files = await this.plugin.getFilesOnLoad();

const templates = this.plugin.textGenerator.getTemplates(
// get files, it will be empty onLoad, that's why we are using this function
files
);

Expand Down
2 changes: 1 addition & 1 deletion src/ui/settings/settings-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class TextGeneratorSettingTab extends PluginSettingTab {
.createDiv("el", (el) => {
el.addClass("tags");
el.createEl("a", {
text: `Version ${packageJson.version}`,
text: `Version ${this.plugin.manifest.version}`,
cls: "tag",
});
el.createEl("a", {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/tool/tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import useStateView from "../context/useStateView";
import MarkDownViewer from "../components/Markdown";
import TemplateInputModalView from "../template-input-modal/view";

export default function ChatComp(props: {
export default function Tool(props: {
plugin: TextGeneratorPlugin;
setCommands: (commands: Command[]) => void;
view: ToolView;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/api-request-formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default class ReqFormatter {

if (
!params.messages?.length &&
params.prompt?.replaceAll("\n", "").trim().length
params.prompt?.replaceAll?.("\n", "").trim().length
) {
bodyParams.messages.push({ role: "user", content: params.prompt || "" });
}
Expand Down

0 comments on commit b332f03

Please sign in to comment.