slike 0.2.0__tar.gz → 0.2.2__tar.gz
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.
- {slike-0.2.0 → slike-0.2.2}/.gitignore +2 -1
- {slike-0.2.0 → slike-0.2.2}/PKG-INFO +458 -3
- slike-0.2.2/README.md +1040 -0
- slike-0.2.2/js/README.md +754 -0
- {slike-0.2.0 → slike-0.2.2}/pyproject.toml +1 -1
- {slike-0.2.0 → slike-0.2.2}/slike.py +299 -6
- {slike-0.2.0 → slike-0.2.2}/slikeupload.py +24 -3
- slike-0.2.0/README.md +0 -585
- slike-0.2.0/js/README.md +0 -356
- {slike-0.2.0 → slike-0.2.2}/LICENSE +0 -0
- {slike-0.2.0 → slike-0.2.2}/config.example.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: slike
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Python SDK for publishing media on Slike platform
|
|
5
5
|
Project-URL: Homepage, https://code.sli.ke/python/slike-media-package
|
|
6
6
|
Project-URL: Documentation, https://code.sli.ke/python/slike-media-package#readme
|
|
@@ -31,7 +31,7 @@ Description-Content-Type: text/markdown
|
|
|
31
31
|
|
|
32
32
|
Python and TypeScript/JavaScript SDK for the [Slike](https://sli.ke) platform.
|
|
33
33
|
|
|
34
|
-
Supports **chunked file upload** (4 MiB chunks), **editor-video registration**, **publish-by-URL** (Google Drive, YouTube, direct links), **media status checks**,
|
|
34
|
+
Supports **chunked file upload** (4 MiB chunks), **editor-video registration**, **publish-by-URL** (Google Drive, YouTube, direct links), **media status checks**, **metadata retrieval**, **agency listing**, **media update**, **upload cancellation** (local + server-side), **CMS user creation**, and **team-by-host lookup**. Two auth flows: **direct Slike token** or **Denmark JWT**.
|
|
35
35
|
|
|
36
36
|
- Python requires **3.7+**
|
|
37
37
|
- TypeScript/JS requires **Node 18+** (or modern browser with Fetch API)
|
|
@@ -114,11 +114,29 @@ result = client.register_media(
|
|
|
114
114
|
asset_type="video", # optional, default: "video"
|
|
115
115
|
tags=["news", "sports"], # optional
|
|
116
116
|
preset_config={"meta": "", "social": ""}, # optional
|
|
117
|
+
team="team-id", # optional, team ID from get_required_metadata
|
|
118
|
+
business="biz-id", # optional, business ID paired with team
|
|
119
|
+
agency="agency-id", # optional, agency ID from get_agency_list
|
|
117
120
|
on_progress=lambda done, total: print(f"{done}/{total} chunks"),
|
|
118
121
|
)
|
|
119
122
|
print("Media ID:", result["id"])
|
|
120
123
|
```
|
|
121
124
|
|
|
125
|
+
Pass `team` and its paired `business` together — both come from the same team object returned by `get_required_metadata`:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
meta = client.get_required_metadata()
|
|
129
|
+
selected_team = meta["default_team"]["team"] # or whichever team the user picks
|
|
130
|
+
|
|
131
|
+
result = client.register_media(
|
|
132
|
+
file_path="/path/to/video.mp4",
|
|
133
|
+
title="My Video",
|
|
134
|
+
description="Description",
|
|
135
|
+
team=selected_team["value"],
|
|
136
|
+
business=selected_team["business"],
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
122
140
|
**Non-blocking file upload** (upload runs in a background thread; callback fires the moment chunks finish):
|
|
123
141
|
|
|
124
142
|
```python
|
|
@@ -198,6 +216,104 @@ threading.Timer(5.0, client.cancel).start()
|
|
|
198
216
|
|
|
199
217
|
---
|
|
200
218
|
|
|
219
|
+
#### `get_required_metadata`
|
|
220
|
+
|
|
221
|
+
Fetch all dropdown options for building a media-update form. Returns static constants at the top level, per-team filtered languages and categories, and a flat agency list.
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
meta = client.get_required_metadata()
|
|
225
|
+
|
|
226
|
+
# Static constants (from SDK)
|
|
227
|
+
print(meta["content_types"]) # [{"value": "package", "label": "Package"}, ...]
|
|
228
|
+
print(meta["production_types"]) # [{"value": "In House Originals", "label": "In House Originals"}, ...]
|
|
229
|
+
print(meta["content_ratings"]) # [{"value": "1", "label": "Made for Kids"}, ...]
|
|
230
|
+
print(meta["media_states"]) # [{"value": 0, "label": "Draft"}, ...]
|
|
231
|
+
|
|
232
|
+
# Agencies (flat list sorted by recent activity)
|
|
233
|
+
for agency in meta["agencies"]:
|
|
234
|
+
print(agency["id"], agency["name"])
|
|
235
|
+
|
|
236
|
+
# Default team (pre-select on load); None if no teams exist
|
|
237
|
+
print(meta["default_team"]["team"]) # {"value": "team-id-1", "label": "Team 1", "is_default": True, "business": "biz-id"}
|
|
238
|
+
print(meta["default_team"]["languages"]) # [{"value": "Language 1", "label": "Language 1"}, ...]
|
|
239
|
+
print(meta["default_team"]["categories"]) # [{"value": "Category 1", "label": "Category 1", "subcategories": [...]}, ...]
|
|
240
|
+
|
|
241
|
+
# All teams (populate team switcher)
|
|
242
|
+
for entry in meta["teams"]:
|
|
243
|
+
print(entry["team"]) # {"value": ..., "label": ..., "is_default": ..., "business": ...}
|
|
244
|
+
print(entry["languages"]) # languages allowed for this team
|
|
245
|
+
print(entry["categories"]) # categories allowed for this team
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
#### `get_agency_list`
|
|
251
|
+
|
|
252
|
+
List active agencies, optionally filtered by name. Returns up to 50 results sorted by recent activity.
|
|
253
|
+
|
|
254
|
+
```python
|
|
255
|
+
# All active agencies
|
|
256
|
+
result = client.get_agency_list()
|
|
257
|
+
print(result["count"]) # total count
|
|
258
|
+
for a in result["list"]:
|
|
259
|
+
print(a["id"], a["name"])
|
|
260
|
+
|
|
261
|
+
# Search by name
|
|
262
|
+
result = client.get_agency_list(name="toi")
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
| Parameter | Type | Description |
|
|
266
|
+
|---|---|---|
|
|
267
|
+
| `name` | `str` | Optional name filter |
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
#### `update_media`
|
|
272
|
+
|
|
273
|
+
Update metadata fields on an existing media item. All fields except `id` are optional — only provided fields are sent.
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
result = client.update_media(
|
|
277
|
+
id="media-id-here",
|
|
278
|
+
title="Updated Title",
|
|
279
|
+
desc="Updated description",
|
|
280
|
+
tags=["news", "sports"],
|
|
281
|
+
lang="English",
|
|
282
|
+
category="News",
|
|
283
|
+
subcategory="Politics",
|
|
284
|
+
ctype="story",
|
|
285
|
+
production_type="In House Originals",
|
|
286
|
+
mfk=2, # content rating: 1=Kids, 2=General, 3=18+
|
|
287
|
+
media_state=1, # 0=Draft, 1=Active
|
|
288
|
+
expiry="2026-12-31",
|
|
289
|
+
youtube_id="dQw4w9WgXcQ",
|
|
290
|
+
parentid="parent-id",
|
|
291
|
+
)
|
|
292
|
+
print(result) # dict with updated media fields
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
| Parameter | Type | Description |
|
|
296
|
+
|---|---|---|
|
|
297
|
+
| `id` | `str` | **Required.** Media ID to update |
|
|
298
|
+
| `title` | `str` | **Required.** Media title |
|
|
299
|
+
| `title_url` | `str` | URL-friendly title slug |
|
|
300
|
+
| `desc` | `str` | Description |
|
|
301
|
+
| `tags` | `list[str]` | Tags |
|
|
302
|
+
| `agency_credits` | `list[str]` | Agency credits |
|
|
303
|
+
| `ctype` | `str` | Content type (see `CONTENT_TYPES`) |
|
|
304
|
+
| `production_type` | `str` | Production type (see `PRODUCTION_TYPES`) |
|
|
305
|
+
| `lang` | `str` | Language name |
|
|
306
|
+
| `category` | `str` | Category name |
|
|
307
|
+
| `subcategory` | `str` | Sub-category name |
|
|
308
|
+
| `mfk` | `int` | Content rating: `1`=Kids, `2`=General, `3`=18+ |
|
|
309
|
+
| `images` | `dict` | Image metadata |
|
|
310
|
+
| `expiry` | `str` | Expiry date string |
|
|
311
|
+
| `youtube_id` | `str` | YouTube video ID |
|
|
312
|
+
| `parentid` | `str` | Parent media ID |
|
|
313
|
+
| `media_state` | `int` | `0`=Draft, `1`=Active |
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
201
317
|
#### `cancel_upload`
|
|
202
318
|
|
|
203
319
|
Cancel a specific upload and **notify the Slike server** to mark the media as cancelled (calls `media.update` with cancel status values). Use this when the user explicitly cancels from the UI.
|
|
@@ -240,6 +356,82 @@ client.publish_media(
|
|
|
240
356
|
|
|
241
357
|
---
|
|
242
358
|
|
|
359
|
+
#### `create_user`
|
|
360
|
+
|
|
361
|
+
Create a CMS user. Send only `name`, `email` and `team` (a list of team ids);
|
|
362
|
+
the backend fills in all remaining user defaults. Calls the `user.createcms` RPC
|
|
363
|
+
on the **accounts endpoint** (`https://accounts.sli.ke/rpc`, dev
|
|
364
|
+
`https://accounts-dev.sli.ke/rpc`).
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
result = client.create_user(
|
|
368
|
+
name="Test User",
|
|
369
|
+
email="test.user@example.com",
|
|
370
|
+
team=["nd78ug9zoo", "ndbxuuzzko"],
|
|
371
|
+
)
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Returns a concise confirmation:
|
|
375
|
+
|
|
376
|
+
```python
|
|
377
|
+
{
|
|
378
|
+
"id": "ws41sgoouo",
|
|
379
|
+
"name": "Test User",
|
|
380
|
+
"email": "test.user@example.com",
|
|
381
|
+
"msg": "User 'Test User' created successfully with id ws41sgoouo.",
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
Equivalent raw request (same call the SDK makes):
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
curl -X POST https://accounts.sli.ke/rpc \
|
|
389
|
+
-H "Content-Type: application/json" \
|
|
390
|
+
--cookie "token=<YOUR_SLIKE_TOKEN>" \
|
|
391
|
+
-d '{
|
|
392
|
+
"jsonrpc": "2.0",
|
|
393
|
+
"id": 1,
|
|
394
|
+
"method": "user.createcms",
|
|
395
|
+
"params": {
|
|
396
|
+
"name": "Test User",
|
|
397
|
+
"email": "test.user@example.com",
|
|
398
|
+
"team": ["nd78ug9zoo", "ndbxuuzzko"]
|
|
399
|
+
}
|
|
400
|
+
}'
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
Dev uses `https://accounts-dev.sli.ke/rpc` with cookie `token-dev=<...>`. The token
|
|
404
|
+
may also be sent as a `token` header (`-H "token: <...>"`) — the JS SDK uses the
|
|
405
|
+
header form. The raw reply is `{"result": {"id": "...", ...}}`.
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
#### `get_teams_by_host`
|
|
410
|
+
|
|
411
|
+
List the teams attached to a host. Calls the `team.byhost` RPC on the same
|
|
412
|
+
**accounts endpoint**. Multiple teams can share a host, so the result is always a list.
|
|
413
|
+
|
|
414
|
+
```python
|
|
415
|
+
teams = client.get_teams_by_host(hostid="153")
|
|
416
|
+
for t in teams:
|
|
417
|
+
print(t["id"], t["name"], t["hostid"])
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
| Parameter | Type | Description |
|
|
421
|
+
|---|---|---|
|
|
422
|
+
| `hostid` | `str` | Host id to look up (required) |
|
|
423
|
+
|
|
424
|
+
Returns a list of `{ "id", "name", "hostid" }`:
|
|
425
|
+
|
|
426
|
+
```python
|
|
427
|
+
[
|
|
428
|
+
{"id": "nd78ug9zoo", "name": "Team A", "hostid": "153"},
|
|
429
|
+
{"id": "ndbxuuzzko", "name": "Team B", "hostid": "153"},
|
|
430
|
+
]
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
---
|
|
434
|
+
|
|
243
435
|
### Error handling
|
|
244
436
|
|
|
245
437
|
```python
|
|
@@ -255,8 +447,35 @@ except CancelError:
|
|
|
255
447
|
print("Upload was cancelled")
|
|
256
448
|
except SlikeAPIError as e:
|
|
257
449
|
print(f"API error: {e} (code: {e.code})")
|
|
450
|
+
if e.conflicts:
|
|
451
|
+
for c in e.conflicts:
|
|
452
|
+
print(f" conflict: field={c['field']} id={c['id']} value={c['value']}")
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
#### Duplicate file (unique constraint)
|
|
456
|
+
|
|
457
|
+
When a file with the same `fid` (derived from filename + size) is already registered on the server, `register_media` raises `SlikeAPIError` with `conflicts` populated:
|
|
458
|
+
|
|
459
|
+
```python
|
|
460
|
+
except SlikeAPIError as e:
|
|
461
|
+
if e.conflicts:
|
|
462
|
+
# File already exists — e.conflicts[0]["id"] is the existing media ID
|
|
463
|
+
existing_id = e.conflicts[0]["id"]
|
|
464
|
+
print(f"Already uploaded as media ID: {existing_id}")
|
|
465
|
+
else:
|
|
466
|
+
print(f"API error: {e} (code: {e.code})")
|
|
258
467
|
```
|
|
259
468
|
|
|
469
|
+
`SlikeAPIError` fields:
|
|
470
|
+
|
|
471
|
+
| Field | Type | Description |
|
|
472
|
+
|---|---|---|
|
|
473
|
+
| `message` | `str` | Human-readable error message |
|
|
474
|
+
| `code` | `int \| None` | HTTP or RPC error code (e.g. `400`) |
|
|
475
|
+
| `conflicts` | `list[dict] \| None` | Conflict entries when a unique constraint is violated |
|
|
476
|
+
|
|
477
|
+
Each conflict entry has `field`, `id`, and `value` keys.
|
|
478
|
+
|
|
260
479
|
---
|
|
261
480
|
|
|
262
481
|
## TypeScript / JavaScript SDK
|
|
@@ -311,11 +530,29 @@ const result = await client.uploadMedia({
|
|
|
311
530
|
title: 'My Video',
|
|
312
531
|
description: 'Description',
|
|
313
532
|
tags: ['news', 'sports'],
|
|
533
|
+
team: 'team-id', // optional — from getRequiredMetadata
|
|
534
|
+
business: 'biz-id', // optional — paired with team
|
|
535
|
+
agency: 'agency-id', // optional — from getAgencyList
|
|
314
536
|
onProgress: (done, total) => console.log(`${done}/${total}`),
|
|
315
537
|
signal: abortController.signal, // optional AbortSignal
|
|
316
538
|
});
|
|
317
539
|
```
|
|
318
540
|
|
|
541
|
+
Pass `team` and `business` together — both come from the same team object:
|
|
542
|
+
|
|
543
|
+
```typescript
|
|
544
|
+
const meta = await client.getRequiredMetadata();
|
|
545
|
+
const selectedTeam = meta.defaultTeam?.team; // or whichever team the user picks
|
|
546
|
+
|
|
547
|
+
const result = await client.uploadMedia({
|
|
548
|
+
file,
|
|
549
|
+
title: 'My Video',
|
|
550
|
+
description: 'Description',
|
|
551
|
+
team: selectedTeam?.value,
|
|
552
|
+
business: selectedTeam?.business,
|
|
553
|
+
});
|
|
554
|
+
```
|
|
555
|
+
|
|
319
556
|
#### `uploadMediaBackground(opts)` — non-blocking upload
|
|
320
557
|
|
|
321
558
|
Returns an `UploadHandle` immediately. `onUploadComplete` fires the moment chunks finish — caller does not need to wait.
|
|
@@ -365,6 +602,138 @@ console.log(status.isReady); // true when status===5 and state===10
|
|
|
365
602
|
console.log(status.msg); // "Media is ready." or "Media is not ready yet."
|
|
366
603
|
```
|
|
367
604
|
|
|
605
|
+
#### `getRequiredMetadata(signal?)`
|
|
606
|
+
|
|
607
|
+
Fetch all dropdown options for building a media-update form. Returns static constants at the top level, per-team filtered languages and categories, and a flat agency list.
|
|
608
|
+
|
|
609
|
+
```typescript
|
|
610
|
+
const meta = await client.getRequiredMetadata();
|
|
611
|
+
|
|
612
|
+
// Static constants (from SDK)
|
|
613
|
+
console.log(meta.contentTypes); // [{ value: 'package', label: 'Package' }, ...]
|
|
614
|
+
console.log(meta.productionTypes); // [{ value: 'In House Originals', label: 'In House Originals' }, ...]
|
|
615
|
+
console.log(meta.contentRatings); // [{ value: '1', label: 'Made for Kids' }, ...]
|
|
616
|
+
console.log(meta.mediaStates); // [{ value: 0, label: 'Draft' }, ...]
|
|
617
|
+
|
|
618
|
+
// Agencies (flat list sorted by recent activity)
|
|
619
|
+
console.log(meta.agencies); // [{ id: 'agency-id', name: 'Agency Name' }, ...]
|
|
620
|
+
|
|
621
|
+
// Default team (pre-select on load)
|
|
622
|
+
console.log(meta.defaultTeam.team); // { value: 'team-id-1', label: 'Team 1', is_default: true, business: 'biz-id' }
|
|
623
|
+
console.log(meta.defaultTeam.languages); // [{ value: 'language-1', label: 'Language 1' }, ...]
|
|
624
|
+
console.log(meta.defaultTeam.categories); // [{ value: 'category-1', label: 'Category 1', subcategories: [...] }, ...]
|
|
625
|
+
|
|
626
|
+
// All teams (populate team switcher)
|
|
627
|
+
meta.teams.forEach(({ team, languages, categories }) => {
|
|
628
|
+
console.log(team); // { value, label, is_default, business }
|
|
629
|
+
console.log(languages); // languages allowed for this team
|
|
630
|
+
console.log(categories); // categories allowed for this team
|
|
631
|
+
});
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
You can also import the static constants directly:
|
|
635
|
+
|
|
636
|
+
```typescript
|
|
637
|
+
import { CONTENT_TYPES, PRODUCTION_TYPES, CONTENT_RATINGS, MEDIA_STATES } from 'slike';
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
**Example response:**
|
|
641
|
+
|
|
642
|
+
```json
|
|
643
|
+
{
|
|
644
|
+
"contentTypes": [{ "value": "content-type-1", "label": "Content Type 1" }],
|
|
645
|
+
"productionTypes": [{ "value": "production-type-1", "label": "Production Type 1" }],
|
|
646
|
+
"contentRatings": [{ "value": "1", "label": "Rating 1" }],
|
|
647
|
+
"mediaStates": [{ "value": 0, "label": "State 1" }],
|
|
648
|
+
"agencies": [{ "id": "agency-id-1", "name": "Agency Name" }],
|
|
649
|
+
"defaultTeam": {
|
|
650
|
+
"team": { "value": "team-id-1", "label": "Team 1", "is_default": true, "business": "biz-id-1" },
|
|
651
|
+
"languages": [{ "value": "language-1", "label": "Language 1" }],
|
|
652
|
+
"categories": [{ "value": "category-1", "label": "Category 1", "subcategories": [{ "value": "sub-category-1", "label": "Sub Category 1" }] }]
|
|
653
|
+
},
|
|
654
|
+
"teams": [
|
|
655
|
+
{
|
|
656
|
+
"team": { "value": "team-id-1", "label": "Team 1", "is_default": true, "business": "biz-id-1" },
|
|
657
|
+
"languages": [{ "value": "language-1", "label": "Language 1" }],
|
|
658
|
+
"categories": [{ "value": "category-1", "label": "Category 1", "subcategories": [] }]
|
|
659
|
+
},
|
|
660
|
+
{
|
|
661
|
+
"team": { "value": "team-id-2", "label": "Team 2", "is_default": false, "business": "biz-id-1" },
|
|
662
|
+
"languages": [{ "value": "language-1", "label": "Language 1" }],
|
|
663
|
+
"categories": [{ "value": "category-1", "label": "Category 1", "subcategories": [{ "value": "sub-category-1", "label": "Sub Category 1" }] }]
|
|
664
|
+
}
|
|
665
|
+
]
|
|
666
|
+
}
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
#### `getAgencyList(opts?, signal?)`
|
|
670
|
+
|
|
671
|
+
List active agencies, optionally filtered by name. Returns up to 50 results sorted by recent activity.
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
// All active agencies
|
|
675
|
+
const result = await client.getAgencyList();
|
|
676
|
+
console.log(result.count); // total count
|
|
677
|
+
console.log(result.list); // [{ id: 'agency-id', name: 'Agency Name' }, ...]
|
|
678
|
+
|
|
679
|
+
// Search by name
|
|
680
|
+
const byName = await client.getAgencyList({ name: 'toi' });
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
`AgencySearchOptions`:
|
|
684
|
+
|
|
685
|
+
| Field | Type | Description |
|
|
686
|
+
|---|---|---|
|
|
687
|
+
| `name` | `string` | Optional name filter |
|
|
688
|
+
|
|
689
|
+
`AgencyListResult`: `{ list: AgencyOption[]; count: number }`
|
|
690
|
+
`AgencyOption`: `{ id: string; name: string }`
|
|
691
|
+
|
|
692
|
+
#### `updateMedia(opts, signal?)`
|
|
693
|
+
|
|
694
|
+
Update metadata fields on an existing media item. All fields except `id` are optional.
|
|
695
|
+
|
|
696
|
+
```typescript
|
|
697
|
+
const result = await client.updateMedia({
|
|
698
|
+
id: 'media-id-here',
|
|
699
|
+
title: 'Updated Title',
|
|
700
|
+
desc: 'Updated description',
|
|
701
|
+
tags: ['news', 'sports'],
|
|
702
|
+
lang: 'English',
|
|
703
|
+
category: 'News',
|
|
704
|
+
subcategory: 'Politics',
|
|
705
|
+
ctype: 'story',
|
|
706
|
+
productionType: 'In House Originals',
|
|
707
|
+
mfk: 2, // content rating: 1=Kids, 2=General, 3=18+
|
|
708
|
+
media_state: 1, // 0=Draft, 1=Active
|
|
709
|
+
expiry: '2026-12-31',
|
|
710
|
+
youtube_id: 'dQw4w9WgXcQ',
|
|
711
|
+
parentid: 'parent-id',
|
|
712
|
+
});
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
`UpdateMediaOptions`:
|
|
716
|
+
|
|
717
|
+
| Field | Type | Description |
|
|
718
|
+
|---|---|---|
|
|
719
|
+
| `id` | `string` | **Required.** Media ID to update |
|
|
720
|
+
| `title` | `string` | **Required.** Media title |
|
|
721
|
+
| `title_url` | `string` | URL-friendly title slug |
|
|
722
|
+
| `desc` | `string` | Description |
|
|
723
|
+
| `tags` | `string[]` | Tags |
|
|
724
|
+
| `agency_credits` | `string[]` | Agency credits |
|
|
725
|
+
| `ctype` | `string` | Content type (see `CONTENT_TYPES`) |
|
|
726
|
+
| `productionType` | `string` | Production type (see `PRODUCTION_TYPES`) |
|
|
727
|
+
| `lang` | `string` | Language name |
|
|
728
|
+
| `category` | `string` | Category name |
|
|
729
|
+
| `subcategory` | `string` | Sub-category name |
|
|
730
|
+
| `mfk` | `number` | Content rating: `1`=Kids, `2`=General, `3`=18+ |
|
|
731
|
+
| `images` | `object` | Image metadata |
|
|
732
|
+
| `expiry` | `string` | Expiry date string |
|
|
733
|
+
| `youtube_id` | `string` | YouTube video ID |
|
|
734
|
+
| `parentid` | `string` | Parent media ID |
|
|
735
|
+
| `media_state` | `0 \| 1` | `0`=Draft, `1`=Active |
|
|
736
|
+
|
|
368
737
|
#### `cancelUpload(mediaId, signal?)`
|
|
369
738
|
|
|
370
739
|
Mark a specific media as cancelled on the Slike server (calls `media.update` with cancel status values). Use when the user explicitly cancels from the UI and you need the server to reflect that.
|
|
@@ -390,6 +759,53 @@ await client.publishMedia({
|
|
|
390
759
|
|
|
391
760
|
---
|
|
392
761
|
|
|
762
|
+
#### `createUser(opts, signal?)`
|
|
763
|
+
|
|
764
|
+
Create a CMS user. Provide only `name`, `email` and `team` (an array of team ids);
|
|
765
|
+
the backend fills in all remaining user defaults. Calls the `user.createcms` RPC
|
|
766
|
+
on the **accounts endpoint** (`https://accounts.sli.ke/rpc`, dev
|
|
767
|
+
`https://accounts-dev.sli.ke/rpc`).
|
|
768
|
+
|
|
769
|
+
```typescript
|
|
770
|
+
const result = await client.createUser({
|
|
771
|
+
name: 'Test User',
|
|
772
|
+
email: 'test.user@example.com',
|
|
773
|
+
team: ['nd78ug9zoo', 'ndbxuuzzko'],
|
|
774
|
+
});
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
Returns a concise confirmation:
|
|
778
|
+
|
|
779
|
+
```typescript
|
|
780
|
+
{
|
|
781
|
+
id: 'ws41sgoouo',
|
|
782
|
+
name: 'Test User',
|
|
783
|
+
email: 'test.user@example.com',
|
|
784
|
+
msg: "User 'Test User' created successfully with id ws41sgoouo.",
|
|
785
|
+
}
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
---
|
|
789
|
+
|
|
790
|
+
#### `getTeamsByHost(hostid, signal?)`
|
|
791
|
+
|
|
792
|
+
List the teams attached to a host. Calls the `team.byhost` RPC on the same
|
|
793
|
+
**accounts endpoint**. Multiple teams can share a host, so the result is always an array.
|
|
794
|
+
|
|
795
|
+
```typescript
|
|
796
|
+
const teams = await client.getTeamsByHost('153');
|
|
797
|
+
// [{ id: 'nd78ug9zoo', name: 'Team A', hostid: '153' }, ...]
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
| Parameter | Type | Description |
|
|
801
|
+
|---|---|---|
|
|
802
|
+
| `hostid` | `string` | Host id to look up (required) |
|
|
803
|
+
| `signal` | `AbortSignal` | Optional abort signal |
|
|
804
|
+
|
|
805
|
+
Returns `HostTeam[]` — a list of `{ id, name, hostid }`.
|
|
806
|
+
|
|
807
|
+
---
|
|
808
|
+
|
|
393
809
|
### Error handling (TypeScript)
|
|
394
810
|
|
|
395
811
|
```typescript
|
|
@@ -401,11 +817,44 @@ try {
|
|
|
401
817
|
if (err instanceof CancelError) {
|
|
402
818
|
console.log('Upload cancelled');
|
|
403
819
|
} else if (err instanceof SlikeAPIError) {
|
|
404
|
-
console.error('API error:', err.message);
|
|
820
|
+
console.error('API error:', err.message, 'code:', err.code);
|
|
821
|
+
if (err.conflicts) {
|
|
822
|
+
for (const c of err.conflicts) {
|
|
823
|
+
console.log(`conflict: field=${c.field} id=${c.id} value=${c.value}`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
#### Duplicate file (unique constraint)
|
|
831
|
+
|
|
832
|
+
When a file with the same `fid` is already registered, `registerMedia` throws `SlikeAPIError` with the message _"This file has already been uploaded…"_ and `conflicts` populated:
|
|
833
|
+
|
|
834
|
+
```typescript
|
|
835
|
+
import { SlikeAPIError, type ConflictEntry } from 'slike';
|
|
836
|
+
|
|
837
|
+
try {
|
|
838
|
+
await client.registerMedia({ file, title: 'T', description: 'D' });
|
|
839
|
+
} catch (err) {
|
|
840
|
+
if (err instanceof SlikeAPIError && err.conflicts) {
|
|
841
|
+
// File already exists — err.conflicts[0].id is the existing media ID
|
|
842
|
+
const existing = err.conflicts[0];
|
|
843
|
+
console.log(`Already uploaded as media ID: ${existing.id}`);
|
|
405
844
|
}
|
|
406
845
|
}
|
|
407
846
|
```
|
|
408
847
|
|
|
848
|
+
`SlikeAPIError` fields:
|
|
849
|
+
|
|
850
|
+
| Field | Type | Description |
|
|
851
|
+
|---|---|---|
|
|
852
|
+
| `message` | `string` | Human-readable error message |
|
|
853
|
+
| `code` | `number \| undefined` | HTTP or RPC error code (e.g. `400`) |
|
|
854
|
+
| `conflicts` | `ConflictEntry[] \| undefined` | Conflict entries when a unique constraint is violated |
|
|
855
|
+
|
|
856
|
+
`ConflictEntry` fields: `field`, `id`, `value`.
|
|
857
|
+
|
|
409
858
|
---
|
|
410
859
|
|
|
411
860
|
## Use Cases
|
|
@@ -588,6 +1037,12 @@ slike-upload video.mp4 --title "T" --desc "D" --denmark-token <jwt>
|
|
|
588
1037
|
|
|
589
1038
|
**Cancel upload (`cancel_upload` / `cancelUpload`):** stops local chunk threads and calls `media.update` RPC with `status=-2, state=-2, media_status=-1` to mark the media cancelled on the server.
|
|
590
1039
|
|
|
1040
|
+
**Required metadata (`get_required_metadata` / `getRequiredMetadata`):** fires `batch.lists` (keys: `["language", "category", "team"]`) and `agency.list` in parallel. Filters languages and categories to `status === 1`, groups them per team using each team's `meta.language` and `meta.category` ID allowlists, and surfaces `business` (business ID) on each team. Returns `agencies` (flat `[{id, name}]` list), `defaultTeam` (team with `is_default: true`), all `teams` with their filtered dropdowns, and static SDK constants at the top level.
|
|
1041
|
+
|
|
1042
|
+
**Agency list (`get_agency_list` / `getAgencyList`):** calls `agency.list` RPC with a standard descending sort by activity. Adds a `must` filter only when `name` or `status` is provided.
|
|
1043
|
+
|
|
1044
|
+
**Media update (`update_media` / `updateMedia`):** calls `media.update` RPC with only the fields you provide — omitted fields are not sent.
|
|
1045
|
+
|
|
591
1046
|
---
|
|
592
1047
|
|
|
593
1048
|
## Development
|