1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
export const upscaleThisUrl = async (req, res) => {
const authToken = process.env.REPLICATE_API_TOKEN;
const url = "https://api.replicate.com/v1/predictions";
const jobId = req.body.jobId;
const imageUrl = req.body.imageUrl;
if (!jobId && !imageUrl) {
res.status(400).json({
error:
"You must pass either a jobId or an imageUrl. You did not pass either.",
});
}
if (jobId && imageUrl) {
res.status(400).json({
error:
"You must pass either a jobId or an imageUrl. You cannot pass both.",
});
}
if (imageUrl) {
const body = {
version:
"660d922d33153019e8c263a3bba265de882e7f4f70396546b6c9c8f9d47a021a",
input: {
image: imageUrl,
},
};
const result = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Token ${authToken}`,
"Content-Type": "application/json",
},
body: JSON.stringify(body),
});
const json = await result.json();
res.send(json);
}
if (jobId) {
const result = await fetch(url + "/" + jobId, {
method: "GET",
headers: {
"Authorization": `Token ${authToken}`,
"Content-Type": "application/json",
},
});
const json = await result.json();
res.send(json);
}
};