@ryuu-reinzz/haruka-lib 2.0.2 → 2.0.4

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.
@@ -1,4 +1,4 @@
1
- import { existsSync, readFile, writeFile } from 'fs-extra';
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';
@@ -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
- import sharp, { fit } from 'sharp';
1
+ import sharp from 'sharp';
2
2
  import videoToGif from './videoToGif.js';
3
- import { writeFile } from 'fs-extra';
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
@@ -25,18 +25,18 @@ const convert = async (data, mime, { quality = 100, background = defaultBg, type
25
25
  switch (type) {
26
26
  case StickerTypes.CROPPED:
27
27
  img.resize(512, 512, {
28
- fit: fit.cover
28
+ fit: sharp.fit.cover
29
29
  });
30
30
  break;
31
31
  case StickerTypes.FULL:
32
32
  img.resize(512, 512, {
33
- fit: fit.contain,
33
+ fit: sharp.fit.contain,
34
34
  background
35
35
  });
36
36
  break;
37
37
  case StickerTypes.CIRCLE:
38
38
  img.resize(512, 512, {
39
- fit: fit.cover
39
+ fit: sharp.fit.cover
40
40
  }).composite([
41
41
  {
42
42
  input: Buffer.from(`<svg width="512" height="512"><circle cx="256" cy="256" r="256" fill="${background}"/></svg>`),
@@ -48,7 +48,7 @@ const convert = async (data, mime, { quality = 100, background = defaultBg, type
48
48
  break;
49
49
  case StickerTypes.ROUNDED:
50
50
  img.resize(512, 512, {
51
- fit: fit.cover
51
+ fit: sharp.fit.cover
52
52
  }).composite([
53
53
  {
54
54
  input: Buffer.from(`<svg width="512" height="512"><rect rx="50" ry="50" width="512" height="512" fill="${background}"/></svg>`),
@@ -1,5 +1,5 @@
1
1
  import Ffmpeg from 'fluent-ffmpeg';
2
- import { readFile } from 'fs-extra';
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 { readFile } from 'fs-extra';
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 { writeFile, readFile, unlink } from 'fs-extra';
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuu-reinzz/haruka-lib",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Library extra for bot WhatsApp",
5
5
  "main": "main/index.js",
6
6
  "type": "module",