Skip to content

Commit

Permalink
Update import
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Nov 26, 2024
1 parent 7ef7f56 commit 3bee4a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Core/Utils/Encoder.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { execFileSync } from "child_process";
import FFmpeg from "fluent-ffmpeg";
import { existsSync, promises as fsp } from "fs";
import { existsSync } from "fs";
import { tmpdir } from "os";
import path, { join } from "path";
import { getMediaInfo } from "./MediaInfo";
import { writeFile } from "fs/promises";
import { mkdtemp, rename, unlink, writeFile } from "fs/promises";
import { Readable } from "stream";
import { ReadableStream } from "stream/web";

Expand All @@ -27,7 +27,7 @@ export class Encoder {

public async encode(input: string, filename: string, duration: number): Promise<string> {
if (!this.cacheDir || !existsSync(this.cacheDir)) {
this.cacheDir = await fsp.mkdtemp(join(tmpdir(), "musicbot-"));
this.cacheDir = await mkdtemp(join(tmpdir(), "musicbot-"));
}

const cacheFile = join(this.cacheDir, filename);
Expand Down Expand Up @@ -63,13 +63,13 @@ export class Encoder {
return reject(err);
})
.on("end", async () => {
await fsp.rename(savePath + ".tmp", savePath);
await rename(savePath + ".tmp", savePath);
if (Math.abs((await getMediaInfo(savePath)).duration - duration) > 1) {
reject(Error("Duration mismatch"));
} else {
resolve(savePath);
}
await fsp.unlink(cacheFile);
await unlink(cacheFile);
});
});
}
Expand Down
6 changes: 3 additions & 3 deletions dist/Core/Utils/Encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Encoder {
}
async encode(input, filename, duration) {
if (!this.cacheDir || !(0, fs_1.existsSync)(this.cacheDir)) {
this.cacheDir = await fs_1.promises.mkdtemp((0, path_1.join)((0, os_1.tmpdir)(), "musicbot-"));
this.cacheDir = await (0, promises_1.mkdtemp)((0, path_1.join)((0, os_1.tmpdir)(), "musicbot-"));
}
const cacheFile = (0, path_1.join)(this.cacheDir, filename);
await this.download(input, cacheFile);
Expand Down Expand Up @@ -88,14 +88,14 @@ class Encoder {
return reject(err);
})
.on("end", async () => {
await fs_1.promises.rename(savePath + ".tmp", savePath);
await (0, promises_1.rename)(savePath + ".tmp", savePath);
if (Math.abs((await (0, MediaInfo_1.getMediaInfo)(savePath)).duration - duration) > 1) {
reject(Error("Duration mismatch"));
}
else {
resolve(savePath);
}
await fs_1.promises.unlink(cacheFile);
await (0, promises_1.unlink)(cacheFile);
});
});
}
Expand Down

0 comments on commit 3bee4a4

Please sign in to comment.