@@ -4,6 +4,7 @@ import { posix } from './create-paths';
44import { AuthenticationClientService } from '../auth/authentication-client-service' ;
55import { ArduinoPreferences } from '../arduino-preferences' ;
66import { SketchCache } from '../widgets/cloud-sketchbook/cloud-sketch-cache' ;
7+ import { Create , CreateError } from './typings' ;
78
89export interface ResponseResultProvider {
910 ( response : Response ) : Promise < any > ;
@@ -19,7 +20,7 @@ type ResourceType = 'f' | 'd';
1920@injectable ( )
2021export class CreateApi {
2122 @inject ( SketchCache )
22- protected readonly sketchCache : SketchCache ;
23+ protected sketchCache : SketchCache ;
2324
2425 protected authenticationService : AuthenticationClientService ;
2526 protected arduinoPreferences : ArduinoPreferences ;
@@ -34,10 +35,6 @@ export class CreateApi {
3435 return this ;
3536 }
3637
37- public wipeCache ( ) : void {
38- this . sketchCache . init ( ) ;
39- }
40-
4138 getSketchSecretStat ( sketch : Create . Sketch ) : Create . Resource {
4239 return {
4340 href : `${ sketch . href } ${ posix . sep } ${ Create . arduino_secrets_file } ` ,
@@ -50,7 +47,7 @@ export class CreateApi {
5047 } ;
5148 }
5249
53- async sketch ( id : string ) : Promise < Create . Sketch | undefined > {
50+ async sketch ( id : string ) : Promise < Create . Sketch > {
5451 const url = new URL ( `${ this . domain ( ) } /sketches/byID/${ id } ` ) ;
5552
5653 url . searchParams . set ( 'user_id' , 'me' ) ;
@@ -303,7 +300,9 @@ export class CreateApi {
303300 secrets : { data : secrets } ,
304301 } ;
305302
306- // replace the sketch in the cache, so other calls will not overwrite each other
303+ // replace the sketch in the cache with the one we are pushing
304+ // TODO: we should do a get after the POST, in order to be sure the cache
305+ // is updated the most recent metadata
307306 this . sketchCache . addSketch ( sketch ) ;
308307
309308 const init = {
@@ -316,6 +315,14 @@ export class CreateApi {
316315 return ;
317316 }
318317
318+ // do not upload "do_not_sync" files/directoris and their descendants
319+ const segments = posixPath . split ( posix . sep ) || [ ] ;
320+ if (
321+ segments . some ( ( segment ) => Create . do_not_sync_files . includes ( segment ) )
322+ ) {
323+ return ;
324+ }
325+
319326 const url = new URL (
320327 `${ this . domain ( ) } /files/f/$HOME/sketches_v2${ posixPath } `
321328 ) ;
@@ -458,76 +465,3 @@ void loop() {
458465
459466` ;
460467}
461-
462- export namespace Create {
463- export interface Sketch {
464- readonly name : string ;
465- readonly path : string ;
466- readonly modified_at : string ;
467- readonly created_at : string ;
468-
469- readonly secrets ?: { name : string ; value : string } [ ] ;
470-
471- readonly id : string ;
472- readonly is_public : boolean ;
473- // readonly board_fqbn: '',
474- // readonly board_name: '',
475- // readonly board_type: 'serial' | 'network' | 'cloud' | '',
476- readonly href ?: string ;
477- readonly libraries : string [ ] ;
478- // readonly tutorials: string[] | null;
479- // readonly types: string[] | null;
480- // readonly user_id: string;
481- }
482-
483- export type ResourceType = 'sketch' | 'folder' | 'file' ;
484- export const arduino_secrets_file = 'arduino_secrets.h' ;
485- export interface Resource {
486- readonly name : string ;
487- /**
488- * Note: this path is **not** the POSIX path we use. It has the leading segments with the `user_id`.
489- */
490- readonly path : string ;
491- readonly type : ResourceType ;
492- readonly sketchId ?: string ;
493- readonly modified_at : string ; // As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
494- readonly created_at : string ; // As an ISO-8601 formatted string: `YYYY-MM-DDTHH:mm:ss.sssZ`
495- readonly children ?: number ; // For 'sketch' and 'folder' types.
496- readonly size ?: number ; // For 'sketch' type only.
497- readonly isPublic ?: boolean ; // For 'sketch' type only.
498-
499- readonly mimetype ?: string ; // For 'file' type.
500- readonly href ?: string ;
501- }
502- export namespace Resource {
503- export function is ( arg : any ) : arg is Resource {
504- return (
505- ! ! arg &&
506- 'name' in arg &&
507- typeof arg [ 'name' ] === 'string' &&
508- 'path' in arg &&
509- typeof arg [ 'path' ] === 'string' &&
510- 'type' in arg &&
511- typeof arg [ 'type' ] === 'string' &&
512- 'modified_at' in arg &&
513- typeof arg [ 'modified_at' ] === 'string' &&
514- ( arg [ 'type' ] === 'sketch' ||
515- arg [ 'type' ] === 'folder' ||
516- arg [ 'type' ] === 'file' )
517- ) ;
518- }
519- }
520-
521- export type RawResource = Omit < Resource , 'sketchId' | 'isPublic' > ;
522- }
523-
524- export class CreateError extends Error {
525- constructor (
526- message : string ,
527- readonly status : number ,
528- readonly details ?: string
529- ) {
530- super ( message ) ;
531- Object . setPrototypeOf ( this , CreateError . prototype ) ;
532- }
533- }
0 commit comments