@@ -2,66 +2,24 @@ import { MaybePromise } from '@theia/core/lib/common/types';
2
2
import { inject , injectable } from '@theia/core/shared/inversify' ;
3
3
import { fetch } from 'cross-fetch' ;
4
4
import { SketchesService } from '../../common/protocol' ;
5
+ import { unit8ArrayToString } from '../../common/utils' ;
5
6
import { ArduinoPreferences } from '../arduino-preferences' ;
6
7
import { AuthenticationClientService } from '../auth/authentication-client-service' ;
7
8
import { SketchCache } from '../widgets/cloud-sketchbook/cloud-sketch-cache' ;
8
9
import * as createPaths from './create-paths' ;
9
10
import { posix } from './create-paths' ;
10
11
import { Create , CreateError } from './typings' ;
11
12
12
- export interface ResponseResultProvider {
13
+ interface ResponseResultProvider {
13
14
// eslint-disable-next-line @typescript-eslint/no-explicit-any
14
15
( response : Response ) : Promise < any > ;
15
16
}
16
- export namespace ResponseResultProvider {
17
+ namespace ResponseResultProvider {
17
18
export const NOOP : ResponseResultProvider = async ( ) => undefined ;
18
19
export const TEXT : ResponseResultProvider = ( response ) => response . text ( ) ;
19
20
export const JSON : ResponseResultProvider = ( response ) => response . json ( ) ;
20
21
}
21
22
22
- // TODO: check if this is still needed: https://github.com/electron/electron/issues/18733
23
- // The original issue was reported for Electron 5.x and 6.x. Theia uses 15.x
24
- export function Utf8ArrayToStr ( array : Uint8Array ) : string {
25
- let out , i , c ;
26
- let char2 , char3 ;
27
-
28
- out = '' ;
29
- const len = array . length ;
30
- i = 0 ;
31
- while ( i < len ) {
32
- c = array [ i ++ ] ;
33
- switch ( c >> 4 ) {
34
- case 0 :
35
- case 1 :
36
- case 2 :
37
- case 3 :
38
- case 4 :
39
- case 5 :
40
- case 6 :
41
- case 7 :
42
- // 0xxxxxxx
43
- out += String . fromCharCode ( c ) ;
44
- break ;
45
- case 12 :
46
- case 13 :
47
- // 110x xxxx 10xx xxxx
48
- char2 = array [ i ++ ] ;
49
- out += String . fromCharCode ( ( ( c & 0x1f ) << 6 ) | ( char2 & 0x3f ) ) ;
50
- break ;
51
- case 14 :
52
- // 1110 xxxx 10xx xxxx 10xx xxxx
53
- char2 = array [ i ++ ] ;
54
- char3 = array [ i ++ ] ;
55
- out += String . fromCharCode (
56
- ( ( c & 0x0f ) << 12 ) | ( ( char2 & 0x3f ) << 6 ) | ( ( char3 & 0x3f ) << 0 )
57
- ) ;
58
- break ;
59
- }
60
- }
61
-
62
- return out ;
63
- }
64
-
65
23
type ResourceType = 'f' | 'd' ;
66
24
67
25
@injectable ( )
@@ -330,10 +288,9 @@ export class CreateApi {
330
288
if ( sketch ) {
331
289
const url = new URL ( `${ this . domain ( ) } /sketches/${ sketch . id } ` ) ;
332
290
const headers = await this . headers ( ) ;
333
-
334
291
// parse the secret file
335
292
const secrets = (
336
- typeof content === 'string' ? content : Utf8ArrayToStr ( content )
293
+ typeof content === 'string' ? content : unit8ArrayToString ( content )
337
294
)
338
295
. split ( / \r ? \n / )
339
296
. reduce ( ( prev , curr ) => {
@@ -397,7 +354,7 @@ export class CreateApi {
397
354
const headers = await this . headers ( ) ;
398
355
399
356
let data : string =
400
- typeof content === 'string' ? content : Utf8ArrayToStr ( content ) ;
357
+ typeof content === 'string' ? content : unit8ArrayToString ( content ) ;
401
358
data = await this . toggleSecretsInclude ( posixPath , data , 'remove' ) ;
402
359
403
360
const payload = { data : btoa ( data ) } ;
0 commit comments