@homebridge/hap-client 1.10.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +15 -0
- package/.github/FUNDING.yml +4 -0
- package/.github/homebridge-reddit.svg +179 -0
- package/.github/npm-version-script.js +93 -0
- package/.github/workflows/beta-release.yml +31 -0
- package/.github/workflows/build.yml +18 -0
- package/.github/workflows/codeql-analysis.yml +13 -0
- package/.github/workflows/release-drafter.yml +14 -0
- package/.github/workflows/release.yml +24 -0
- package/.github/workflows/stale.yml +12 -0
- package/.vscode/settings.json +10 -0
- package/LICENSE +674 -0
- package/README.md +9 -0
- package/dist/eventedHttpClient/httpParser.d.ts +27 -0
- package/dist/eventedHttpClient/httpParser.js +237 -0
- package/dist/eventedHttpClient/httpParser.js.map +1 -0
- package/dist/eventedHttpClient/index.d.ts +4 -0
- package/dist/eventedHttpClient/index.js +50 -0
- package/dist/eventedHttpClient/index.js.map +1 -0
- package/dist/hap-types.d.ts +714 -0
- package/dist/hap-types.js +718 -0
- package/dist/hap-types.js.map +1 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +377 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +113 -0
- package/dist/interfaces.js +3 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/monitor.d.ts +14 -0
- package/dist/monitor.js +93 -0
- package/dist/monitor.js.map +1 -0
- package/dist/uuid.d.ts +2 -0
- package/dist/uuid.js +23 -0
- package/dist/uuid.js.map +1 -0
- package/package.json +58 -0
- package/scripts/gen-hap-types.ts +62 -0
- package/scripts/test.ts +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# hap-client
|
|
2
|
+
|
|
3
|
+
## License
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2019 oznu
|
|
6
|
+
|
|
7
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU General Public License](./LICENSE) for more details.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
declare function httpMessageParser(message: any): {
|
|
3
|
+
protocol: any;
|
|
4
|
+
httpVersion: any;
|
|
5
|
+
statusCode: any;
|
|
6
|
+
statusMessage: any;
|
|
7
|
+
method: any;
|
|
8
|
+
url: any;
|
|
9
|
+
headers: any;
|
|
10
|
+
body: any;
|
|
11
|
+
boundary: any;
|
|
12
|
+
multipart: any;
|
|
13
|
+
additional: any;
|
|
14
|
+
};
|
|
15
|
+
declare namespace httpMessageParser {
|
|
16
|
+
var _isTruthy: (v: any) => boolean;
|
|
17
|
+
var _isNumeric: (v: any) => boolean;
|
|
18
|
+
var _isBuffer: (item: any) => any;
|
|
19
|
+
var _isNodeBufferSupported: () => boolean;
|
|
20
|
+
var _parseHeaders: (body: any) => {};
|
|
21
|
+
var _requestLineRegex: RegExp;
|
|
22
|
+
var _responseLineRegex: RegExp;
|
|
23
|
+
var _headerNewlineRegex: RegExp;
|
|
24
|
+
var _boundaryRegex: RegExp;
|
|
25
|
+
var _createBuffer: (data: any) => Buffer;
|
|
26
|
+
}
|
|
27
|
+
export default httpMessageParser;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function httpMessageParser(message) {
|
|
4
|
+
const result = {
|
|
5
|
+
protocol: null,
|
|
6
|
+
httpVersion: null,
|
|
7
|
+
statusCode: null,
|
|
8
|
+
statusMessage: null,
|
|
9
|
+
method: null,
|
|
10
|
+
url: null,
|
|
11
|
+
headers: null,
|
|
12
|
+
body: null,
|
|
13
|
+
boundary: null,
|
|
14
|
+
multipart: null,
|
|
15
|
+
additional: null,
|
|
16
|
+
};
|
|
17
|
+
let messageString = '';
|
|
18
|
+
let headerNewlineIndex = 0;
|
|
19
|
+
let fullBoundary = null;
|
|
20
|
+
if (httpMessageParser._isBuffer(message)) {
|
|
21
|
+
messageString = message.toString();
|
|
22
|
+
}
|
|
23
|
+
else if (typeof message === 'string') {
|
|
24
|
+
messageString = message;
|
|
25
|
+
message = httpMessageParser._createBuffer(messageString);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
messageString = messageString.replace(/\r\n/gim, '\n');
|
|
31
|
+
(function () {
|
|
32
|
+
const firstNonWhitespaceRegex = /[\w-]+/gim;
|
|
33
|
+
const firstNonWhitespaceIndex = messageString.search(firstNonWhitespaceRegex);
|
|
34
|
+
if (firstNonWhitespaceIndex > 0) {
|
|
35
|
+
message = message.slice(firstNonWhitespaceIndex, message.length);
|
|
36
|
+
messageString = message.toString();
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
(function () {
|
|
40
|
+
const possibleRequestLine = messageString.split(/\n|\r\n/)[0];
|
|
41
|
+
const requestLineMatch = possibleRequestLine.match(httpMessageParser._requestLineRegex);
|
|
42
|
+
if (Array.isArray(requestLineMatch) && requestLineMatch.length > 1) {
|
|
43
|
+
result.protocol = requestLineMatch[1];
|
|
44
|
+
result.httpVersion = parseFloat(requestLineMatch[2]);
|
|
45
|
+
result.statusCode = parseInt(requestLineMatch[3], 10);
|
|
46
|
+
result.statusMessage = requestLineMatch[4];
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const responseLineMath = possibleRequestLine.match(httpMessageParser._responseLineRegex);
|
|
50
|
+
if (Array.isArray(responseLineMath) && responseLineMath.length > 1) {
|
|
51
|
+
result.method = responseLineMath[1];
|
|
52
|
+
result.url = responseLineMath[2];
|
|
53
|
+
result.httpVersion = parseFloat(responseLineMath[3]);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
(function () {
|
|
58
|
+
headerNewlineIndex = messageString.search(httpMessageParser._headerNewlineRegex);
|
|
59
|
+
if (headerNewlineIndex > -1) {
|
|
60
|
+
headerNewlineIndex = headerNewlineIndex + 1;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
if (result.httpVersion) {
|
|
64
|
+
headerNewlineIndex = messageString.length;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const headersString = messageString.substr(0, headerNewlineIndex);
|
|
68
|
+
const headers = httpMessageParser._parseHeaders(headersString);
|
|
69
|
+
if (Object.keys(headers).length > 0) {
|
|
70
|
+
result.headers = headers;
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
(function () {
|
|
74
|
+
if (!result.boundary) {
|
|
75
|
+
const boundaryMatch = messageString.match(httpMessageParser._boundaryRegex);
|
|
76
|
+
if (Array.isArray(boundaryMatch) && boundaryMatch.length) {
|
|
77
|
+
fullBoundary = boundaryMatch[0].replace(/[\r\n]+/gi, '');
|
|
78
|
+
const boundary = fullBoundary.replace(/^--/, '');
|
|
79
|
+
result.boundary = boundary;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
})();
|
|
83
|
+
(function () {
|
|
84
|
+
let start = headerNewlineIndex;
|
|
85
|
+
let end = (result.headers && result.headers['Content-Length'] ? result.headers['Content-Length'] + start : messageString.length);
|
|
86
|
+
const firstBoundaryIndex = messageString.indexOf(fullBoundary);
|
|
87
|
+
if (firstBoundaryIndex > -1 && result.boundary) {
|
|
88
|
+
start = headerNewlineIndex;
|
|
89
|
+
end = firstBoundaryIndex;
|
|
90
|
+
}
|
|
91
|
+
if (headerNewlineIndex > -1) {
|
|
92
|
+
const body = messageString.slice(start, end);
|
|
93
|
+
result.additional = messageString.slice(end);
|
|
94
|
+
if (body && body.length) {
|
|
95
|
+
if ((result.headers && result.headers['Content-Type'] === 'application/hap+json') ||
|
|
96
|
+
(result.headers && result.headers['Content-Type'] === 'application/json')) {
|
|
97
|
+
try {
|
|
98
|
+
if (result.headers['Content-Length']) {
|
|
99
|
+
result.body = body;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
result.body = body.split('\n')[1];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
result.body = body;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})();
|
|
114
|
+
(function () {
|
|
115
|
+
if (result.boundary) {
|
|
116
|
+
const multipartStart = messageString.indexOf(fullBoundary) + fullBoundary.length;
|
|
117
|
+
const multipartEnd = messageString.lastIndexOf(fullBoundary);
|
|
118
|
+
const multipartBody = messageString.substr(multipartStart, multipartEnd);
|
|
119
|
+
const splitRegex = new RegExp('^' + fullBoundary + '.*[\n\r]?$', 'gm');
|
|
120
|
+
const parts = multipartBody.split(splitRegex);
|
|
121
|
+
result.multipart = parts.filter(httpMessageParser._isTruthy).map(function (part, i) {
|
|
122
|
+
const result = {
|
|
123
|
+
headers: null,
|
|
124
|
+
body: null,
|
|
125
|
+
meta: {
|
|
126
|
+
body: {
|
|
127
|
+
byteOffset: {
|
|
128
|
+
start: null,
|
|
129
|
+
end: null,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
const newlineRegex = /\n\n|\r\n\r\n/gim;
|
|
135
|
+
let newlineIndex = 0;
|
|
136
|
+
let newlineMatch = newlineRegex.exec(part);
|
|
137
|
+
let body = null;
|
|
138
|
+
if (newlineMatch) {
|
|
139
|
+
newlineIndex = newlineMatch.index;
|
|
140
|
+
if (newlineMatch.index <= 0) {
|
|
141
|
+
newlineMatch = newlineRegex.exec(part);
|
|
142
|
+
if (newlineMatch) {
|
|
143
|
+
newlineIndex = newlineMatch.index;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
const possibleHeadersString = part.substr(0, newlineIndex);
|
|
148
|
+
let startOffset = null;
|
|
149
|
+
let endOffset = null;
|
|
150
|
+
if (newlineIndex > -1) {
|
|
151
|
+
const headers = httpMessageParser._parseHeaders(possibleHeadersString);
|
|
152
|
+
if (Object.keys(headers).length > 0) {
|
|
153
|
+
result.headers = headers;
|
|
154
|
+
const boundaryIndexes = [];
|
|
155
|
+
for (let j = 0; j >= 0;) {
|
|
156
|
+
j = message.indexOf(fullBoundary, j);
|
|
157
|
+
if (j >= 0) {
|
|
158
|
+
boundaryIndexes.push(j);
|
|
159
|
+
j += fullBoundary.length;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const boundaryNewlineIndexes = [];
|
|
163
|
+
boundaryIndexes.slice(0, boundaryIndexes.length - 1).forEach(function (m, k) {
|
|
164
|
+
const partBody = message.slice(boundaryIndexes[k], boundaryIndexes[k + 1]).toString();
|
|
165
|
+
let headerNewlineIndex = partBody.search(/\n\n|\r\n\r\n/gim) + 2;
|
|
166
|
+
headerNewlineIndex = boundaryIndexes[k] + headerNewlineIndex;
|
|
167
|
+
boundaryNewlineIndexes.push(headerNewlineIndex);
|
|
168
|
+
});
|
|
169
|
+
startOffset = boundaryNewlineIndexes[i];
|
|
170
|
+
endOffset = boundaryIndexes[i + 1];
|
|
171
|
+
body = message.slice(startOffset, endOffset);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
body = part;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
body = part;
|
|
179
|
+
}
|
|
180
|
+
result.body = body;
|
|
181
|
+
result.meta.body.byteOffset.start = startOffset;
|
|
182
|
+
result.meta.body.byteOffset.end = endOffset;
|
|
183
|
+
return result;
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
})();
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
httpMessageParser._isTruthy = function _isTruthy(v) {
|
|
190
|
+
return !!v;
|
|
191
|
+
};
|
|
192
|
+
httpMessageParser._isNumeric = function _isNumeric(v) {
|
|
193
|
+
if (typeof v === 'number' && !isNaN(v)) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
v = (v || '').toString().trim();
|
|
197
|
+
if (!v) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return !isNaN(v);
|
|
201
|
+
};
|
|
202
|
+
httpMessageParser._isBuffer = function (item) {
|
|
203
|
+
return ((httpMessageParser._isNodeBufferSupported() &&
|
|
204
|
+
typeof global === 'object' &&
|
|
205
|
+
global.Buffer.isBuffer(item)) ||
|
|
206
|
+
(item instanceof Object &&
|
|
207
|
+
item._isBuffer));
|
|
208
|
+
};
|
|
209
|
+
httpMessageParser._isNodeBufferSupported = function () {
|
|
210
|
+
return (typeof global === 'object' &&
|
|
211
|
+
typeof global.Buffer === 'function' &&
|
|
212
|
+
typeof global.Buffer.isBuffer === 'function');
|
|
213
|
+
};
|
|
214
|
+
httpMessageParser._parseHeaders = function _parseHeaders(body) {
|
|
215
|
+
const headers = {};
|
|
216
|
+
if (typeof body !== 'string') {
|
|
217
|
+
return headers;
|
|
218
|
+
}
|
|
219
|
+
body.split(/[\r\n]/).forEach(function (string) {
|
|
220
|
+
const match = string.match(/([\w-]+):\s*(.*)/i);
|
|
221
|
+
if (Array.isArray(match) && match.length === 3) {
|
|
222
|
+
const key = match[1];
|
|
223
|
+
const value = match[2];
|
|
224
|
+
headers[key] = httpMessageParser._isNumeric(value) ? Number(value) : value;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return headers;
|
|
228
|
+
};
|
|
229
|
+
httpMessageParser._requestLineRegex = /(HTTP|EVENT)\/(1\.0|1\.1|2\.0)\s+(\d+)\s+([\w\s-_]+)/i;
|
|
230
|
+
httpMessageParser._responseLineRegex = /(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|TRACE|CONNECT)\s+(.*)\s+HTTP\/(1\.0|1\.1|2\.0)/i;
|
|
231
|
+
httpMessageParser._headerNewlineRegex = /^[\r\n]+/gim;
|
|
232
|
+
httpMessageParser._boundaryRegex = /(\n|\r\n)+--[\w-]+(\n|\r\n)+/g;
|
|
233
|
+
httpMessageParser._createBuffer = function (data) {
|
|
234
|
+
return new Buffer(data);
|
|
235
|
+
};
|
|
236
|
+
exports.default = httpMessageParser;
|
|
237
|
+
//# sourceMappingURL=httpParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpParser.js","sourceRoot":"","sources":["../../src/eventedHttpClient/httpParser.ts"],"names":[],"mappings":";;AAOA,SAAS,iBAAiB,CAAC,OAAO;IAChC,MAAM,MAAM,GAAG;QACb,QAAQ,EAAE,IAAI;QACd,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,IAAI;QAChB,aAAa,EAAE,IAAI;QACnB,MAAM,EAAE,IAAI;QACZ,GAAG,EAAE,IAAI;QACT,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;QACd,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;KACjB,CAAC;IAEF,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,kBAAkB,GAAG,CAAC,CAAC;IAC3B,IAAI,YAAY,GAAG,IAAI,CAAC;IAExB,IAAI,iBAAiB,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QACzC,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IACrC,CAAC;SAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QACvC,aAAa,GAAG,OAAO,CAAC;QACxB,OAAO,GAAG,iBAAiB,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC;IAChB,CAAC;IAKD,aAAa,GAAG,aAAa,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAKvD,CAAC;QACC,MAAM,uBAAuB,GAAG,WAAW,CAAC;QAC5C,MAAM,uBAAuB,GA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vB,OAAO,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC7E,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF,iBAAiB,CAAC,iBAAiB,GAAG,uDAAuD,CAAC;AAC9F,iBAAiB,CAAC,kBAAkB,GAAG,yFAAyF,CAAC;AAEjI,iBAAiB,CAAC,mBAAmB,GAAG,aAAa,CAAC;AACtD,iBAAiB,CAAC,cAAc,GAAG,+BAA+B,CAAC;AAEnE,iBAAiB,CAAC,aAAa,GAAG,UAAU,IAAI;IAE9C,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC,CAAC;AAEF,kBAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createConnection = exports.parseMessage = void 0;
|
|
4
|
+
const node_net_1 = require("node:net");
|
|
5
|
+
const node_url_1 = require("node:url");
|
|
6
|
+
const httpParser_1 = require("./httpParser");
|
|
7
|
+
exports.parseMessage = httpParser_1.default;
|
|
8
|
+
function createConnection(instance, pin, body) {
|
|
9
|
+
const client = (0, node_net_1.createConnection)({
|
|
10
|
+
host: instance.ipAddress,
|
|
11
|
+
port: instance.port,
|
|
12
|
+
});
|
|
13
|
+
client.write(_buildMessage({
|
|
14
|
+
method: 'PUT',
|
|
15
|
+
url: 'http://' + instance.ipAddress + ':' + instance.port + '/characteristics',
|
|
16
|
+
maxAttempts: 1,
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'Application/json',
|
|
19
|
+
'authorization': pin,
|
|
20
|
+
'connection': 'keep-alive',
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify(body),
|
|
23
|
+
}));
|
|
24
|
+
return client;
|
|
25
|
+
}
|
|
26
|
+
exports.createConnection = createConnection;
|
|
27
|
+
function _headersToString(headers) {
|
|
28
|
+
let response = '';
|
|
29
|
+
for (const header of Object.keys(headers)) {
|
|
30
|
+
response = response + header + ': ' + headers[header] + '\r\n';
|
|
31
|
+
}
|
|
32
|
+
return (response);
|
|
33
|
+
}
|
|
34
|
+
function _buildMessage(request) {
|
|
35
|
+
const context = (0, node_url_1.parse)(request.url);
|
|
36
|
+
let message;
|
|
37
|
+
message = request.method + ' ' + context.pathname;
|
|
38
|
+
if (context.search) {
|
|
39
|
+
message = message + context.search;
|
|
40
|
+
}
|
|
41
|
+
message = message + ' HTTP/1.1\r\nHost: ' + context.host + '\r\n' + _headersToString(request.headers);
|
|
42
|
+
if (request.body) {
|
|
43
|
+
message = message + 'Content-Length: ' + request.body.length + '\r\n\r\n' + request.body + '\r\n\r\n';
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
message = message + '\r\n\r\n';
|
|
47
|
+
}
|
|
48
|
+
return (message);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/eventedHttpClient/index.ts"],"names":[],"mappings":";;;AAKA,uCAAmE;AACnE,uCAAiC;AAEjC,6CAA6C;AAEhC,QAAA,YAAY,GAAG,oBAAiB,CAAC;AAE9C,SAAgB,gBAAgB,CAAC,QAAQ,EAAE,GAAW,EAAE,IAAI;IAC1D,MAAM,MAAM,GAAG,IAAA,2BAAmB,EAAC;QACjC,IAAI,EAAE,QAAQ,CAAC,SAAS;QACxB,IAAI,EAAE,QAAQ,CAAC,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;QACzB,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,SAAS,GAAG,QAAQ,CAAC,SAAS,GAAG,GAAG,GAAG,QAAQ,CAAC,IA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