forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxep0363.ts
104 lines (96 loc) · 2.66 KB
/
xep0363.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// ====================================================================
// XEP-0363: HTTP File Upload
// --------------------------------------------------------------------
// Source: https://xmpp.org/extensions/xep-0363.html
// Version: 0.5.0 (2018-02-15)
// ====================================================================
import {
attribute,
childAttribute,
childDateAttribute,
childEnum,
deepChildInteger,
DefinitionOptions,
extendStanzaError,
integerAttribute,
text
} from '../jxt';
import { NS_HTTP_UPLOAD_0 } from '../Namespaces';
declare module './' {
export interface IQPayload {
httpUpload?: HTTPUploadRequest | HTTPUploadSlot;
}
export interface StanzaError {
httpUploadError?: 'file-too-large' | 'retry';
httpUploadMaxFileSize?: number;
httpUpoadRetry?: Date;
}
}
export interface HTTPUploadRequest {
type?: 'request';
name: string;
size: number;
mediaType?: string;
}
export interface HTTPUploadSlot {
type?: 'slot';
upload: HTTPUploadLocation;
download: string;
}
export interface HTTPUploadLocation {
url: string;
headers?: HTTPUploadHeader[];
}
export interface HTTPUploadHeader {
name: string;
value: string;
}
const Protocol: DefinitionOptions[] = [
extendStanzaError({
httpUploadError: childEnum(NS_HTTP_UPLOAD_0, ['file-too-large', 'retry']),
httpUploadMaxFileSize: deepChildInteger([
{ namespace: NS_HTTP_UPLOAD_0, element: 'file-too-large' },
{ namespace: NS_HTTP_UPLOAD_0, element: 'max-file-size' }
]),
httpUploadRetry: childDateAttribute(NS_HTTP_UPLOAD_0, 'retry', 'stamp')
}),
{
element: 'request',
fields: {
mediaType: attribute('content-type'),
name: attribute('filename'),
size: integerAttribute('size')
},
namespace: NS_HTTP_UPLOAD_0,
path: 'iq.httpUpload',
type: 'request',
typeField: 'type'
},
{
element: 'slot',
fields: {
download: childAttribute(null, 'get', 'url')
},
namespace: NS_HTTP_UPLOAD_0,
path: 'iq.httpUpload',
type: 'slot'
},
{
aliases: [{ path: 'iq.httpUpload.upload', selector: 'slot' }],
element: 'put',
fields: {
url: attribute('url')
},
namespace: NS_HTTP_UPLOAD_0
},
{
aliases: [{ path: 'iq.httpUpload.upload.headers', multiple: true }],
element: 'header',
fields: {
name: attribute('name'),
value: text()
},
namespace: NS_HTTP_UPLOAD_0
}
];
export default Protocol;