@ryuu-reinzz/haruka-lib 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main/sticker-engine/java-script/Sticker.js +5 -5
- package/main/sticker-engine/java-script/internal/convert.js +2 -2
- package/main/sticker-engine/java-script/internal/crop.js +2 -2
- package/main/sticker-engine/java-script/internal/imagesToWebp.js +2 -2
- package/main/sticker-engine/java-script/internal/videoToGif.js +4 -4
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
import Utils, { defaultBg } from './Utils.js';
|
|
4
4
|
import { fromBuffer } from 'file-type';
|
|
5
5
|
import convert from './internal/convert.js';
|
|
6
6
|
import Exif from './internal/Metadata/Exif.js';
|
|
7
7
|
import { StickerTypes } from './internal/Metadata/StickerTypes.js';
|
|
8
|
-
import { extractMetadata } from '.';
|
|
8
|
+
import { extractMetadata } from './index.js';
|
|
9
9
|
/**
|
|
10
10
|
* Sticker class
|
|
11
11
|
*/
|
|
@@ -22,8 +22,8 @@ export class Sticker {
|
|
|
22
22
|
? this.data
|
|
23
23
|
: this.data.trim().startsWith('<svg')
|
|
24
24
|
? Buffer.from(this.data)
|
|
25
|
-
: (async () => existsSync(this.data)
|
|
26
|
-
? readFile(this.data)
|
|
25
|
+
: (async () => fs.existsSync(this.data)
|
|
26
|
+
? fs.readFile(this.data)
|
|
27
27
|
: axios.get(this.data, { responseType: 'arraybuffer' }).then(({ data }) => data))();
|
|
28
28
|
this._getMimeType = async (data) => {
|
|
29
29
|
const type = await fromBuffer(data);
|
|
@@ -64,7 +64,7 @@ export class Sticker {
|
|
|
64
64
|
* sticker.toFile('./image.webp')
|
|
65
65
|
*/
|
|
66
66
|
this.toFile = async (filename = this.defaultFilename) => {
|
|
67
|
-
await writeFile(filename, await this.build());
|
|
67
|
+
await fs.writeFile(filename, await this.build());
|
|
68
68
|
return filename;
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import sharp, { fit } from 'sharp';
|
|
2
2
|
import videoToGif from './videoToGif.js';
|
|
3
|
-
import
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
4
|
import { tmpdir } from 'os';
|
|
5
5
|
import crop from './crop.js';
|
|
6
6
|
import { StickerTypes } from './Metadata/StickerTypes.js';
|
|
@@ -11,7 +11,7 @@ const convert = async (data, mime, { quality = 100, background = defaultBg, type
|
|
|
11
11
|
const isAnimated = isVideo || mime.includes('gif') || mime.includes('webp');
|
|
12
12
|
if (isAnimated && ['crop', 'circle', 'rouded'].includes(type)) {
|
|
13
13
|
const filename = `${tmpdir()}/${Math.random().toString(36)}.webp`;
|
|
14
|
-
await writeFile(filename, image);
|
|
14
|
+
await fs.writeFile(filename, image);
|
|
15
15
|
[image, type] = [
|
|
16
16
|
await crop(filename),
|
|
17
17
|
type === StickerTypes.CIRCLE
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ffmpeg from 'fluent-ffmpeg';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
3
|
import { tmpdir } from 'os';
|
|
4
4
|
const crop = async (filename) => {
|
|
5
5
|
const file = await new Promise((resolve) => {
|
|
@@ -25,6 +25,6 @@ const crop = async (filename) => {
|
|
|
25
25
|
.save(name)
|
|
26
26
|
.on('end', () => resolve(name));
|
|
27
27
|
});
|
|
28
|
-
return await readFile(file);
|
|
28
|
+
return await fs.readFile(file);
|
|
29
29
|
};
|
|
30
30
|
export default crop;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Ffmpeg from 'fluent-ffmpeg';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
3
|
import { tmpdir } from 'os';
|
|
4
4
|
const imagesToWebp = async (filename) => {
|
|
5
5
|
const file = await new Promise((resolve) => {
|
|
@@ -12,6 +12,6 @@ const imagesToWebp = async (filename) => {
|
|
|
12
12
|
.save(name)
|
|
13
13
|
.on('end', () => resolve(name));
|
|
14
14
|
});
|
|
15
|
-
return await readFile(file);
|
|
15
|
+
return await fs.readFile(file);
|
|
16
16
|
};
|
|
17
17
|
export default imagesToWebp;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import ffmpeg from 'fluent-ffmpeg';
|
|
2
|
-
import
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
3
|
import { tmpdir } from 'os';
|
|
4
4
|
/** https://stackoverflow.com/questions/52156713/fluent-ffmpeg-h264-to-gif-throwing-error-1 */
|
|
5
5
|
const videoToGif = async (data) => {
|
|
6
6
|
const filename = `${tmpdir()}/${Math.random().toString(36)}`;
|
|
7
7
|
const [video, gif] = ['video', 'gif'].map((ext) => `${filename}.${ext}`);
|
|
8
|
-
await writeFile(video, data);
|
|
8
|
+
await fs.writeFile(video, data);
|
|
9
9
|
await new Promise((resolve) => {
|
|
10
10
|
ffmpeg(video).save(gif).on('end', resolve);
|
|
11
11
|
});
|
|
12
|
-
const buffer = await readFile(gif);
|
|
13
|
-
[video, gif].forEach((file) => unlink(file));
|
|
12
|
+
const buffer = await fs.readFile(gif);
|
|
13
|
+
[video, gif].forEach((file) => fs.unlink(file));
|
|
14
14
|
return buffer;
|
|
15
15
|
};
|
|
16
16
|
export default videoToGif;
|