Spaces:
Sleeping

File size: 1,132 Bytes
1305386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { IPayloadPoster } from "../../interfaces/core/IPayloadPoster";
import { IPayloadReference } from "../../interfaces/core/IPayloadReference";
import { IStoragePoster } from "../../interfaces/core/IStoragePoster";

export class PayloadPoster implements IPayloadPoster {
    posters: IStoragePoster[];
    constructor({ posters }: { posters: IStoragePoster[] }) {
        this.posters = posters;
    }
    postPayload = async (params: { payloadReference: IPayloadReference }): Promise<IPayloadReference> => {
        const payloadReference = params.payloadReference;
        if (payloadReference.storageType == "none") {
            return payloadReference;
        }
        // Tìm storage poster phù hợp để xử lý payloadReference
        const foundPoster = this.posters.find(poster => poster.storageType == payloadReference.storageType);
        if (!foundPoster) {
            throw new Error(`Không tìm thấy poster phù hợp để xử lý payload reference`);
        }
        const updatedReference = await foundPoster.post(payloadReference);
        return updatedReference;
    }
}