-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
53 lines (49 loc) · 1.39 KB
/
index.ts
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
52
53
import axios from 'axios';
import * as fs from 'fs';
interface Twibbon {
creator: String,
id:any,
name: String
}
interface TwibbonResponse {
status: boolean,
url?: String
}
class Twibbonizze {
/**
@param name : Twibbon name
*/
name: String;
constructor(name: String) {
this.name = name;
}
async create(Image: fs.PathLike | Buffer):Promise<boolean|String> {
/**
Create Twibon
@param Image: Image Path | Buffer
*/
var buffer: Buffer;
if(Image instanceof String || !(Image instanceof Buffer)){
buffer = fs.readFileSync(Image);
}else if(Image instanceof Buffer){
buffer = Image;
}
const stat:TwibbonResponse = (await axios({
url:'https://twibbonizes.id/create',
method:'post',
data: `name=${this.name}&image=${encodeURIComponent(buffer.toString('base64'))}`,
headers:{},
})).data;
return stat.url || stat.status
};
};
async function twisearch(name: string):Promise<Array<Twibbonizze>> {
/**
Search Twibbon by name
@param name
*/
const result = (await axios.get(`https://twibbonizes.id/search?q=${encodeURIComponent(name)}`)).data;
return result.map((x:Twibbon)=>new Twibbonizze(x.name));
};
module.exports = {twisearch, Twibbonizze};
export default Twibbonizze;