blob: 75ccb5e998f8273afca449cf0d9194c1d08b4bb6 (
plain)
| 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
 | import { Utils } from "../Utils";
import { CurrentUserUtils } from "../server/authentication/models/current_user_utils";
import requestPromise = require('request-promise');
export namespace Identified {
    export async function FetchFromServer(relativeRoute: string) {
        return (await fetch(relativeRoute, { headers: { userId: CurrentUserUtils.id } })).text();
    }
    export async function PostToServer(relativeRoute: string, body?: any) {
        let options = {
            uri: Utils.prepend(relativeRoute),
            method: "POST",
            headers: { userId: CurrentUserUtils.id },
            body,
            json: true
        };
        return requestPromise.post(options);
    }
    export async function PostFormDataToServer(relativeRoute: string, formData: FormData) {
        const parameters = {
            method: 'POST',
            headers: { userId: CurrentUserUtils.id },
            body: formData,
        };
        const response = await fetch(relativeRoute, parameters);
        const text = await response.json();
        return text;
    }
}
 |