-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-spec.yml
More file actions
740 lines (720 loc) · 22.6 KB
/
Copy pathapi-spec.yml
File metadata and controls
740 lines (720 loc) · 22.6 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
openapi: 3.0.3
info:
title: BloomLibrary API
version: "1.0"
servers:
- url: https://api.bloomlibrary.org/v1
- url: https://staging-api.bloomlibrary.org/v1
description: staging (points at the staging Supabase project)
components:
parameters:
PathId:
name: id
in: path
required: true
schema:
type: string
HeaderAuthToken:
name: Authentication-Token
in: header
required: true
schema:
type: string
Lang:
description: comma-separated list of BCP 47 language tags
name: lang
in: query
required: false
schema:
type: string
Uploader:
description: comma-separated list of email addresses
name: uploader
in: query
required: false
schema:
type: string
Environment:
description: which backing data environment to use (defaults to prod)
name: env
in: query
required: false
schema:
type: string
enum:
- dev
- prod
- unit-test
Limit:
name: limit
in: query
description: Number of items to retrieve (unlimited if omitted)
required: false
schema:
type: integer
minimum: 0 # set to 0, for example, if you only want the count
Offset:
name: offset
in: query
description: Number of items to skip
required: false
schema:
type: integer
minimum: 0
Count:
name: count
in: query
description: If true, the result will also contain the count of items
required: false
schema:
type: boolean
Expand:
name: expand
in: query
description: A comma-separated list of fields for which to include the full record
required: false
schema:
type: string
schemas:
Book:
type: object
properties:
id:
type: string
languages:
type: array
items:
$ref: "#/components/schemas/Language"
titles:
type: array
items:
type: object
properties:
lang:
type: string
title:
type: string
required: [lang, title]
uploader:
type: object
properties:
email:
type: string
id:
type: string
required: [email]
# editor uses these, but we don't necessarily want them as part of the public shape
instanceId:
type: string
format: uuid
titleFromUpload:
type: string
baseUrl:
type: string
format: uri
updatedAt:
type: string
format: date-time
createdAt:
type: string
format: date-time
draft:
type: boolean
nullable: true
harvestState:
type: string
brandingProjectName:
type: string
inCirculation:
type: boolean
nullable: true
phashOfFirstContentImage:
type: string
bookLineage:
type: string
lastUploaded:
type: string
format: date-time
tags:
type: array
items:
type: string
summary:
type: string
nullable: true
features:
type: array
items:
type: string
# links:
# type: string
# format: uri
required: [id]
example:
id: 123
languages: [{ "tag": "en" }, { "tag": "fr" }]
titles:
- lang: en
title: Moon & Cap
- lang: fr
title: La lune et le Cap
uploader:
email: bob@example.com
# links: https://api.bloomlibrary.org/books/123/links
Language:
type: object
properties:
id:
description: Unique ID for the language record. Unfortunately, tag is not unique.
type: string
tag:
description: BCP 47 language tag
type: string
name:
type: string
englishName:
type: string
usageCount:
type: integer
required: [tag]
LongRunningOperationCommonResult:
type: object
properties:
id: # the operation ID; used to query for status
type: string
status:
type: string
enum:
- Succeeded
- Running
- Failed
- NotStarted
LongRunningOperationSucceededResult:
allOf:
- $ref: "#/components/schemas/LongRunningOperationCommonResult"
- type: object
properties:
result:
oneOf:
- $ref: "#/components/schemas/UploadStartResult"
- $ref: "#/components/schemas/UploadFinishResult"
LongRunningOperationFailedResult:
allOf:
- $ref: "#/components/schemas/LongRunningOperationCommonResult"
- type: object
properties:
error:
type: object
properties:
code:
type: string
message:
type: string
LongRunningOperationOtherResult:
$ref: "#/components/schemas/LongRunningOperationCommonResult"
UploadStartResult:
type: object
properties:
transactionId:
type: string
credentials:
type: object
properties:
AccessKeyId:
type: string
SecretAccessKey:
type: string
SessionToken:
type: string
url:
type: string
format: uri
filesToUpload:
type: array
items:
type: string
UploadFinishResult:
type: object
SubscriptionResult:
type: object
properties:
code:
type: string
description: The subscription code
replacementCode:
type: string
description: A replacement code if applicable
tier:
type: string
description: The subscription tier
brandingLabel:
type: string
description: Label for branding purposes
showMessage:
type: string
description: Message to display to the user
required: [code, replacementCode, tier, brandingLabel, showMessage]
responses:
BookArray:
description: OK
content:
application/json:
schema:
type: object
properties:
results:
type: array
items:
$ref: "#/components/schemas/Book"
count:
type: integer
AcceptedWithOperationLocation:
description: Accepted
headers:
Operation-Location:
description: URL to check the status of the operation
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/LongRunningOperationCommonResult"
paths:
/books:
get: # 5.7 editor uses to get book count in language: /books?lang=xyz&limit=0&count=true
description: returns an array of books with metadata (and links?)
parameters:
- $ref: "#/components/parameters/Lang"
- $ref: "#/components/parameters/Uploader"
- $ref: "#/components/parameters/Limit"
- $ref: "#/components/parameters/Offset"
- $ref: "#/components/parameters/Count"
- $ref: "#/components/parameters/Expand"
- $ref: "#/components/parameters/Environment"
responses:
200:
$ref: "#/components/responses/BookArray"
# When we get a POST rather than a GET,
# it indicates we must look in the body for
# which books to return.
# Reasoning: the url has a length limit which we avoid by using the body.
# Currently, we need this for bookInstanceIds.
post: # 5.7 editor uses to get blorg badge statuses
description: returns an array of books with metadata
parameters:
- $ref: "#/components/parameters/Lang"
- $ref: "#/components/parameters/Uploader"
- $ref: "#/components/parameters/Environment"
requestBody:
description: array of book instance IDs
required: true
content:
application/json:
schema:
type: object
properties:
instanceIds:
description: A book "instance ID" is a guid found in meta.json; it was designed to be unique but we couldn't keep people from copying using file explorer, so it is not actually unique. It serves as a unique identifier for a book in a particular collection within the editor. In contrast, the "book ID" is the database ID and it is unique.
type: array
items:
type: string
responses:
200:
$ref: "#/components/responses/BookArray"
/books/{id}: # needed by 5.7 editor conflict dialog and SP App team
get:
description: Get metadata for a specific book
parameters:
- $ref: "#/components/parameters/PathId"
- $ref: "#/components/parameters/Expand"
- $ref: "#/components/parameters/Environment"
responses:
200:
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Book"
404:
description: Not Found - no book with that ID
delete: # needed for next round of blorg changes
description: Delete a book
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
responses:
204:
description: No Content
# Gets its own endpoint because it is expensive.
# i.e. we don't want to just return it with each book record.
# Some day, we may have a /books:permissions for collection-level permissions.
# But in Feb 2024, I could not figure out how to define the route in functions.json
# to achieve that along with handling /books /books/{id}.
# To do this, we may have to define a new function with /books{collection-action}.
/books/{id}:permissions: # needed for next round of changes
get:
description: returns whether the user may edit the book
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
responses:
200:
description: OK
content:
application/json:
schema:
type: object
properties:
reupload:
type: boolean
delete:
type: boolean
editSurfaceMetadata:
type: boolean
editAllMetadata:
type: boolean
becomeUploader:
type: boolean
/books/{id}:upload-start: # 5.7 editor uses
post:
description: Initiate upload or reupload of a book. id is "new" if creating a new book. Otherwise, it is the existing book ID.
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
files:
description: Array of relative file paths and their corresponding hashes
type: array
items:
type: object
properties:
path:
type: string
hash:
type: string
name:
description: Any file-system-safe name. Bloom editor uses the folder name. This may become part of the S3 key (and currently does).
type: string
clientName:
description: Name of the client. For Bloom editor, this includes the channel. This may be used to disallow certain channels from uploading, etc.
type: string
clientVersion:
description: Version of the client. This may be used to disallow certain versions from uploading, etc.
type: string
required:
- files
- clientName
- clientVersion
responses:
202:
$ref: "#/components/responses/AcceptedWithOperationLocation"
/books/{id}:upload-finish: # 5.7 editor uses
post:
description: Finalize uploading a book
parameters:
- $ref: "#/components/parameters/HeaderAuthToken"
- $ref: "#/components/parameters/PathId"
requestBody:
description: The transaction ID
required: true
content:
application/json:
schema:
type: object
properties:
transactionId:
type: string
metadata:
type: object
becomeUploader:
description: If true, the book record will be updated to show that the user is now the uploader.
type: boolean
required:
- transactionId
- metadata
responses:
202:
$ref: "#/components/responses/AcceptedWithOperationLocation"
# status is used for long-running operations to check their progress.
# When the job is complete, it returns status:Succeeded and the actual result.
/status/{operation-id}: # 5.7 editor uses
get:
description: returns the status (and result if complete) of a long-running operation
parameters:
- name: operation-id
in: path
description: The operation ID
required: true
schema:
type: string
responses:
200:
description: OK
headers:
Retry-After:
description: Seconds to wait before retrying
schema:
type: integer
content:
application/json:
schema:
oneOf:
- $ref: "#/components/schemas/LongRunningOperationSucceededResult"
- $ref: "#/components/schemas/LongRunningOperationFailedResult"
- $ref: "#/components/schemas/LongRunningOperationOtherResult"
discriminator:
propertyName: status
mapping:
Succeeded: "#/components/schemas/LongRunningOperationSucceededResult"
Failed: "#/components/schemas/LongRunningOperationFailedResult"
Running: "#/components/schemas/LongRunningOperationOtherResult"
NotStarted: "#/components/schemas/LongRunningOperationOtherResult"
/subscriptionInfo/{code}:
get:
description: Get subscription information for a given code
parameters:
- name: code
in: path
description: The subscription code to look up
required: true
schema:
type: string
responses:
200:
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/SubscriptionResult"
404:
description: Not Found - No subscription found for the given code
# ---------------------------------------------------------------------------
# The endpoints below predate this spec (they were undocumented in the Azure
# repo) and were added when the API migrated to Supabase Edge Functions.
# Note: {filePath} may contain slashes (e.g. thumbnails/thumbnail-256.png);
# OpenAPI has no syntax for multi-segment path parameters.
/fs/{bucket}/{id}/{filePath}:
get:
description:
Streams a file belonging to a book (thumbnail, epub, bloompub, pdf, ...)
without exposing where it is stored. Supports Range and conditional
request headers. Responses for harvest thumbnails are served with a
one-year Cache-Control.
parameters:
- name: bucket
in: path
required: true
schema:
type: string
enum: [upload, dev-upload, harvest, dev-harvest]
- $ref: "#/components/parameters/PathId"
- name: filePath
in: path
description: path of the file within the book folder; may contain slashes
required: true
schema:
type: string
responses:
200:
description: OK - the file contents
content:
"*/*":
schema:
type: string
format: binary
206:
description: Partial Content (Range request)
400:
description: Bad Request - unknown bucket, unknown book, or too few path segments
404:
description: Not Found - the file does not exist
/opds:
get:
description:
Returns an OPDS 1.2 catalog (Atom XML) of Bloom Library books, navigable
by language. Without lang/tag/organizeby parameters, returns the root
navigation document.
parameters:
- name: key
in: query
description:
"API account key of the form email:accountId. Currently optional
(anonymous access is deprecated and will be removed)."
required: false
schema:
type: string
- name: lang
in: query
description: BCP 47 language tag; list only books in this language
required: false
schema:
type: string
- name: tag
in: query
description: list only books with this tag (e.g. list:SEL)
required: false
schema:
type: string
- name: epub
in: query
description: if true, only include books with a downloadable ePUB
required: false
schema:
type: boolean
- name: organizeby
in: query
required: false
schema:
type: string
enum: [language]
- name: minimalnavlinks
in: query
description: if true, omit self/start/up links and the language facet list
required: false
schema:
type: boolean
- name: src
in: query
description: which backing data environment to use (defaults to prod)
required: false
schema:
type: string
enum: [dev, prod]
responses:
200:
description: OK
content:
application/xml: {}
401:
description: Unauthorized - missing/empty key
403:
description: Forbidden - key did not match an API account
503:
description: Service Unavailable - could not validate the key
/social:
get:
description:
Returns an HTML page with OpenGraph metadata so social media sites show
a proper preview when sharing a Bloom Library link; the page redirects
real visitors to the link. Parameters may also be sent as a POST JSON
body with the same names.
parameters:
- name: link
in: query
description: the bloomlibrary.org URL to share (other domains are rejected)
required: true
schema:
type: string
format: uri
- name: title
in: query
required: true
schema:
type: string
- name: img
in: query
required: false
schema:
type: string
format: uri
- name: width
in: query
description: og:image:width (default 256)
required: false
schema:
type: integer
- name: height
in: query
description: og:image:height (default 256)
required: false
schema:
type: integer
- name: description
in: query
required: false
schema:
type: string
responses:
200:
description: OK
content:
text/html: {}
400:
description: Bad Request - missing link or title
403:
description: Forbidden - link is not on bloomlibrary.org
/stats/{category}/{rowType}:
post:
description:
Returns reading/usage statistics from the analytics database. The set of
books can be scoped either by the filter's own fields or by an embedded
Parse query (parseDBQuery) whose results are used to select books.
parameters:
- name: category
in: path
required: true
schema:
type: string
enum: [reading]
- name: rowType
in: path
required: true
schema:
type: string
enum: [book, per-book, per-day, overview, locations]
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
filter:
type: object
properties:
parseDBQuery:
description:
A Parse REST query (url, method, options with
headers/params/data) whose resulting book IDs scope the
statistics.
type: object
branding:
type: string
country:
type: string
fromDate:
description: YYYY-MM-DD
type: string
toDate:
description: YYYY-MM-DD
type: string
bookId:
description: used by rowType "book"
type: string
bookInstanceId:
description: used by rowType "book"
type: string
required: [filter]
responses:
200:
description: OK
content:
application/json:
schema:
type: object
properties:
stats:
type: array
items:
type: object
400:
description:
Bad Request - missing filter, invalid dates, or unknown
category/rowType (also returned for internal errors, matching
longstanding behavior)