Khrisna commited on
Commit
a30c07d
·
verified ·
1 Parent(s): aa8aa5a

Update lib/enchance.js

Browse files
Files changed (1) hide show
  1. lib/enchance.js +28 -39
lib/enchance.js CHANGED
@@ -1,6 +1,7 @@
1
  import WebSocket from "ws"
2
  import Jimp from "jimp"
3
  import FormData from "form-data"
 
4
 
5
  async function upscaler(images) {
6
  return new Promise((resolve, reject) => {
@@ -50,49 +51,37 @@ async function upscaler(images) {
50
  })
51
 
52
  }
53
- async function processImageUpscaler({ buffer, method, filenames, mimetype }) {
54
- return new Promise(async (resolve, reject) => {
55
- let Methods = ["enhance"];
56
- Methods.includes(method) ? (method = method) : (method = Methods[0]);
57
 
58
- let buffer,
59
- Form = new FormData(),
60
- scheme = "https" + "://" + "inferenceengine" + ".vyro" + ".ai/" + method;
 
61
 
62
- Form.append("model_version", 1);
 
 
63
 
64
- Form.append("image", buffer, {
65
- filename: filenames,
66
- contentType: mimetype,
67
- });
68
 
69
- Form.submit({
70
- url: scheme,
71
- host: "inferenceengine" + ".vyro" + ".ai",
72
- path: "/" + method,
73
- protocol: "https:",
74
- headers: {
75
- "User-Agent": "okhttp/4.9.3",
76
- Connection: "Keep-Alive",
77
- "Accept-Encoding": "gzip",
78
- },
79
- },
80
- function(err, res) {
81
- if (err) reject(err);
82
- let data = [];
83
- res
84
- .on("data", function(chunk) {
85
- data.push(chunk);
86
- })
87
- .on("end", () => {
88
- resolve(Buffer.concat(data));
89
- });
90
- res.on("error", (e) => {
91
- reject(e);
92
- });
93
- }
94
- );
95
  });
96
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  export { upscaler, processImageUpscaler }
 
1
  import WebSocket from "ws"
2
  import Jimp from "jimp"
3
  import FormData from "form-data"
4
+ import axios from "axios"
5
 
6
  async function upscaler(images) {
7
  return new Promise((resolve, reject) => {
 
51
  })
52
 
53
  }
 
 
 
 
54
 
55
+ async function processImageUpscaler({ urlPath, method, filenames, mimetype }) {
56
+ return new Promise(async (resolve, reject) => {
57
+ let Methods = ["enhance"];
58
+ Methods.includes(method)? (method = method) : (method = Methods[0]);
59
 
60
+ let buffer,
61
+ formData = new FormData(),
62
+ scheme = "https://" + "inferenceengine" + ".vyro" + ".ai/" + method;
63
 
64
+ formData.append("model_version", 1);
 
 
 
65
 
66
+ formData.append("image", await fs.promises.readFile(urlPath), {
67
+ filename: filenames,
68
+ contentType: mimetype,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  });
70
+
71
+ const headers = {
72
+ "User-Agent": "okhttp/4.9.3",
73
+ Connection: "Keep-Alive",
74
+ "Accept-Encoding": "gzip",
75
+ };
76
+
77
+ axios.post(scheme, formData, { headers })
78
+ .then(response => {
79
+ resolve(response.data);
80
+ })
81
+ .catch(error => {
82
+ reject(error);
83
+ });
84
+ });
85
+ }
86
 
87
  export { upscaler, processImageUpscaler }