@@ -68,6 +68,7 @@ import {
68
68
type RawListEntry ,
69
69
type RawRemarkableApi ,
70
70
type RequestMethod ,
71
+ type SimpleEntry ,
71
72
type Tag ,
72
73
type TemplateContent ,
73
74
type TextAlignment ,
@@ -94,14 +95,17 @@ export type {
94
95
RawFileEntry ,
95
96
RawListEntry ,
96
97
RawRemarkableApi ,
98
+ SimpleEntry ,
97
99
Tag ,
98
100
TemplateContent ,
99
101
TextAlignment ,
102
+ UploadMimeType ,
100
103
ZoomMode ,
101
104
} from "./raw" ;
102
105
103
106
const AUTH_HOST = "https://webapp-prod.cloud.remarkable.engineering" ;
104
107
const RAW_HOST = "https://eu.tectonic.remarkable.com" ;
108
+ const UPLOAD_HOST = "https://internal.cloud.remarkable.com" ;
105
109
106
110
// ------------ //
107
111
// Request Info //
@@ -165,14 +169,6 @@ export interface TemplateType extends EntryCommon {
165
169
/** a remarkable entry for cloud items */
166
170
export type Entry = CollectionEntry | DocumentType | TemplateType ;
167
171
168
- /** an simple entry without any extra information */
169
- export interface SimpleEntry {
170
- /** the document id */
171
- id : string ;
172
- /** the document hash */
173
- hash : string ;
174
- }
175
-
176
172
/** the new hash of a modified entry */
177
173
export interface HashEntry {
178
174
/** the actual hash */
@@ -185,6 +181,12 @@ export interface HashesEntry {
185
181
hashes : Record < string , string > ;
186
182
}
187
183
184
+ /** options for creating a folder */
185
+ export interface FolderOptions {
186
+ /** the id of the folder's parent directory, "" or omitted for root */
187
+ parent ?: string ;
188
+ }
189
+
188
190
/** An error that gets thrown when the backend while trying to update
189
191
*
190
192
* IF you encounter this error, you likely just need to try th request again. If
@@ -285,12 +287,6 @@ export async function register(
285
287
}
286
288
}
287
289
288
- /** options available when uploading a document */
289
- export interface UploadOptions {
290
- /** an optional parent id to set when uploading */
291
- parent ?: string ;
292
- }
293
-
294
290
/**
295
291
* options for putting a file onto reMarkable
296
292
*
@@ -513,9 +509,9 @@ export interface RemarkableApi {
513
509
) : Promise < SimpleEntry > ;
514
510
515
511
/** create a folder */
516
- createFolder (
512
+ putFolder (
517
513
visibleName : string ,
518
- opts ?: UploadOptions ,
514
+ opts ?: FolderOptions ,
519
515
refresh ?: boolean ,
520
516
) : Promise < SimpleEntry > ;
521
517
@@ -528,16 +524,12 @@ export interface RemarkableApi {
528
524
* ```
529
525
*
530
526
* @remarks
531
- * this is now simply a less powerful version of { @link putEpub | `putEpub`} .
527
+ * this uses a simpler api that works even with schema version 4 .
532
528
*
533
529
* @param visibleName - the name to show for the uploaded epub
534
530
* @param buffer - the epub contents
535
531
*/
536
- uploadEpub (
537
- visibleName : string ,
538
- buffer : Uint8Array ,
539
- opts ?: UploadOptions ,
540
- ) : Promise < SimpleEntry > ;
532
+ uploadEpub ( visibleName : string , buffer : Uint8Array ) : Promise < SimpleEntry > ;
541
533
542
534
/**
543
535
* upload a pdf
@@ -548,16 +540,15 @@ export interface RemarkableApi {
548
540
* ```
549
541
*
550
542
* @remarks
551
- * this is now simply a less powerful version of { @link putPdf | `putPdf`} .
543
+ * this uses a simpler api that works even with schema version 4 .
552
544
*
553
545
* @param visibleName - the name to show for the uploaded epub
554
546
* @param buffer - the epub contents
555
547
*/
556
- uploadPdf (
557
- visibleName : string ,
558
- buffer : Uint8Array ,
559
- opts ?: UploadOptions ,
560
- ) : Promise < SimpleEntry > ;
548
+ uploadPdf ( visibleName : string , buffer : Uint8Array ) : Promise < SimpleEntry > ;
549
+
550
+ /** create a folder using the simple api */
551
+ uploadFolder ( visibleName : string ) : Promise < SimpleEntry > ;
561
552
562
553
/**
563
554
* update content metadata for a document
@@ -739,6 +730,7 @@ class Remarkable implements RemarkableApi {
739
730
constructor (
740
731
userToken : string ,
741
732
rawHost : string ,
733
+ uploadHost : string ,
742
734
cache : Map < string , string | null > ,
743
735
) {
744
736
this . #userToken = userToken ;
@@ -748,6 +740,7 @@ class Remarkable implements RemarkableApi {
748
740
this . #authedFetch( url , { method, body, headers } ) ,
749
741
cache ,
750
742
rawHost ,
743
+ uploadHost ,
751
744
) ;
752
745
}
753
746
@@ -815,8 +808,6 @@ class Remarkable implements RemarkableApi {
815
808
const contentEnt = entries . find ( ( ent ) => ent . id . endsWith ( ".content" ) ) ;
816
809
if ( metaEnt === undefined ) {
817
810
throw new Error ( `couldn't find metadata for hash ${ hash } ` ) ;
818
- } else if ( contentEnt === undefined ) {
819
- throw new Error ( `couldn't find content for hash ${ hash } ` ) ;
820
811
}
821
812
822
813
const [
@@ -832,7 +823,10 @@ class Remarkable implements RemarkableApi {
832
823
content ,
833
824
] = await Promise . all ( [
834
825
this . raw . getMetadata ( metaEnt . hash ) ,
835
- this . raw . getContent ( contentEnt . hash ) ,
826
+ // collections don't always have content, since content only lists tags
827
+ contentEnt === undefined
828
+ ? Promise . resolve ( { fileType : undefined , tags : undefined } )
829
+ : this . raw . getContent ( contentEnt . hash ) ,
836
830
] ) ;
837
831
if ( "templateVersion" in content ) {
838
832
return {
@@ -1074,9 +1068,9 @@ class Remarkable implements RemarkableApi {
1074
1068
}
1075
1069
1076
1070
/** create a folder */
1077
- async createFolder (
1071
+ async putFolder (
1078
1072
visibleName : string ,
1079
- { parent = "" } : UploadOptions = { } ,
1073
+ { parent = "" } : FolderOptions = { } ,
1080
1074
refresh : boolean = false ,
1081
1075
) : Promise < SimpleEntry > {
1082
1076
if ( parent && ! idReg . test ( parent ) ) {
@@ -1142,18 +1136,25 @@ class Remarkable implements RemarkableApi {
1142
1136
async uploadEpub (
1143
1137
visibleName : string ,
1144
1138
buffer : Uint8Array ,
1145
- opts : UploadOptions = { } ,
1146
1139
) : Promise < SimpleEntry > {
1147
- return await this . putEpub ( visibleName , buffer , opts ) ;
1140
+ return await this . raw . uploadFile (
1141
+ visibleName ,
1142
+ buffer ,
1143
+ "application/epub+zip" ,
1144
+ ) ;
1148
1145
}
1149
1146
1150
1147
/** upload a pdf */
1151
1148
async uploadPdf (
1152
1149
visibleName : string ,
1153
1150
buffer : Uint8Array ,
1154
- opts : UploadOptions = { } ,
1155
1151
) : Promise < SimpleEntry > {
1156
- return await this . putPdf ( visibleName , buffer , opts ) ;
1152
+ return await this . raw . uploadFile ( visibleName , buffer , "application/pdf" ) ;
1153
+ }
1154
+
1155
+ /** upload a folder */
1156
+ async uploadFolder ( visibleName : string ) : Promise < SimpleEntry > {
1157
+ return await this . raw . uploadFile ( visibleName , new Uint8Array ( 0 ) , "folder" ) ;
1157
1158
}
1158
1159
1159
1160
/** edit just a content entry */
@@ -1437,6 +1438,13 @@ export interface RemarkableOptions {
1437
1438
*/
1438
1439
syncHost ?: string ;
1439
1440
1441
+ /**
1442
+ * the base url for making upload requests
1443
+ *
1444
+ * @defaultValue "https://internal.cloud.remarkable.com"
1445
+ */
1446
+ uploadHost ?: string ;
1447
+
1440
1448
/**
1441
1449
* the url for making requests using the low-level api
1442
1450
*
@@ -1484,6 +1492,7 @@ export async function remarkable(
1484
1492
{
1485
1493
authHost = AUTH_HOST ,
1486
1494
rawHost = RAW_HOST ,
1495
+ uploadHost = UPLOAD_HOST ,
1487
1496
cache,
1488
1497
maxCacheSize = Infinity ,
1489
1498
} : RemarkableOptions = { } ,
@@ -1505,7 +1514,7 @@ export async function remarkable(
1505
1514
maxCacheSize === Infinity
1506
1515
? new Map ( entries )
1507
1516
: new LruCache ( maxCacheSize , entries ) ;
1508
- return new Remarkable ( userToken , rawHost , cache ) ;
1517
+ return new Remarkable ( userToken , rawHost , uploadHost , cache ) ;
1509
1518
} else {
1510
1519
throw new Error (
1511
1520
"cache was not a valid cache (json string mapping); your cache must be corrupted somehow. Either initialize remarkable without a cache, or fix its format." ,
0 commit comments