v1.1.0
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import type { parserType } from "../index";
|
||||
|
||||
const mediaToObj = (ueuse: any) => {
|
||||
const media = {
|
||||
photo: [] as string[],
|
||||
video: [] as string[],
|
||||
};
|
||||
|
||||
if (ueuse.photo1 !== "" || ueuse.video1 !== "") {
|
||||
if (ueuse.photo1 !== "") {
|
||||
media.photo.push(ueuse.photo1);
|
||||
delete ueuse.photo1;
|
||||
}
|
||||
if (ueuse.photo2 !== "") {
|
||||
media.photo.push(ueuse.photo2);
|
||||
delete ueuse.photo2;
|
||||
}
|
||||
if (ueuse.photo3 !== "") {
|
||||
media.photo.push(ueuse.photo3);
|
||||
delete ueuse.photo3;
|
||||
}
|
||||
if (ueuse.photo4 !== "") {
|
||||
media.photo.push(ueuse.photo4);
|
||||
delete ueuse.photo4;
|
||||
}
|
||||
if (ueuse.video1 !== "") {
|
||||
media.video.push(ueuse.video1);
|
||||
delete ueuse.video1;
|
||||
}
|
||||
}
|
||||
|
||||
ueuse.media = media;
|
||||
|
||||
return ueuse;
|
||||
}
|
||||
|
||||
const Parser: parserType = (data, type, endpoint) => {
|
||||
let result = data;
|
||||
|
||||
if (type === "request") {
|
||||
if (result.media && result.text && endpoint === "ueuse/create") {
|
||||
for (let i = 0; i < result.media.photo.length; i++) {
|
||||
result[`photo${i + 1}`] = result.media.photo[i];
|
||||
}
|
||||
|
||||
for (let i = 0; i < result.media.video.length; i++) {
|
||||
result[`video${i + 1}`] = result.media.video[i];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
if (result["0"] !== undefined && result.success === true) {
|
||||
delete result.success;
|
||||
|
||||
const objData: any[] = Object.values(result);
|
||||
|
||||
for (let i = 0; i < objData.length; i++) {
|
||||
if (endpoint.indexOf("ueuse") !== -1) {
|
||||
objData[i] = mediaToObj(objData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: objData,
|
||||
};
|
||||
}
|
||||
|
||||
if (result.favorite_list !== undefined && result.success === true) {
|
||||
delete result.success;
|
||||
|
||||
const list = result.favorite_list.split(",");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
favorite_list: list,
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export default Parser;
|
||||
Reference in New Issue
Block a user