Skip to content

Commit b870346

Browse files
gobengoAlan Shaw
andauthored
feat: listUploads includes parts property with list of links to CARs that contain it (#2347)
Motivation: * #2343 Why touch the sql files? * the db tests wouldn't run cleanly without these changes. It would try to drop tables but fail due to dependencies on the uuid extension, other cols, etc. I think these changes are safe/good and will help others too but I can remove them if needed --------- Co-authored-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 83d5bbf commit b870346

File tree

12 files changed

+138
-9
lines changed

12 files changed

+138
-9
lines changed

.github/workflows/w3.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
# We want this one to fail if we can't upload to the staging api using the workspace version of the client.
4444
- uses: bahmutov/npm-install@v1
4545
- name: Test upload to staging
46+
# disabled until we can make this succeed while staging is in maintenance mode
47+
# as part of old.web3.storage sunset
48+
continue-on-error: true
4649
run: |
4750
npm run build -w packages/client
4851
echo "$(date --utc --iso-8601=seconds) web3.storage upload test" > ./upload-test-small

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/src/magic.link.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ function createMagicTestmodeBypasss () {
5858
export const magicLinkBypassForE2ETestingInTestmode = createMagicTestmodeBypasss()
5959

6060
function isMagicTestModeToken (token) {
61-
const parsed = JSON.parse(globalThis.atob(token))
61+
let parsed
62+
try {
63+
parsed = JSON.parse(globalThis.atob(token))
64+
} catch {
65+
return false
66+
}
6267
if (parsed.length !== 2) {
6368
// unexpeced parse
6469
return false

packages/api/test/fixtures/pgrest/get-user-uploads.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ export default [
2929
}
3030
],
3131
type: 'Car',
32-
updated: '2021-07-14T19:27:14.934572+00:00'
32+
updated: '2021-07-14T19:27:14.934572+00:00',
33+
parts: []
3334
},
3435
{
3536
_id: '8',
@@ -48,7 +49,8 @@ export default [
4849
}
4950
],
5051
type: 'Car',
51-
updated: '2021-07-14T19:27:14.934572+00:00'
52+
updated: '2021-07-14T19:27:14.934572+00:00',
53+
parts: []
5254
},
5355
{
5456
_id: '1',
@@ -59,7 +61,8 @@ export default [
5961
created: '2021-07-09T16:20:33.946845+00:00',
6062
updated: '2021-07-09T16:20:33.946845+00:00',
6163
deals: [],
62-
pins: []
64+
pins: [],
65+
parts: []
6366
},
6467
{
6568
_id: '2',
@@ -70,7 +73,8 @@ export default [
7073
created: '2021-07-09T10:40:35.408884+00:00',
7174
updated: '2021-07-09T10:40:35.408884+00:00',
7275
deals: [],
73-
pins: []
76+
pins: [],
77+
parts: []
7478
},
7579
{
7680
_id: '3',
@@ -81,6 +85,7 @@ export default [
8185
created: '2021-07-09T10:36:05.862862+00:00',
8286
updated: '2021-07-09T10:36:05.862862+00:00',
8387
deals: [],
84-
pins: []
88+
pins: [],
89+
parts: []
8590
}
8691
]

packages/db/db-client-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export type UploadItem = {
206206
created?: definitions['upload']['inserted_at']
207207
updated?: definitions['upload']['updated_at']
208208
content: ContentItem
209+
backupUrls: definitions['upload']['backup_urls']
209210
}
210211

211212
export type UploadItemOutput = {
@@ -218,6 +219,11 @@ export type UploadItemOutput = {
218219
dagSize?: definitions['content']['dag_size']
219220
pins: Array<PinItemOutput>,
220221
deals: Array<Deal>
222+
/**
223+
* the graph from `cid` can be recreated from the blocks in these parts
224+
* @see https://github.com/web3-storage/content-claims#partition-claim
225+
*/
226+
parts: Array<string>
221227
}
222228

223229
export type UploadOutput = definitions['upload'] & {

packages/db/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const uploadQuery = `
2121
sourceCid:source_cid,
2222
created:inserted_at,
2323
updated:updated_at,
24+
backupUrls:backup_urls,
2425
content(cid, dagSize:dag_size, pins:pin(status, updated:updated_at, location:pin_location(_id:id, peerId:peer_id, peerName:peer_name, ipfsPeerId:ipfs_peer_id, region)))
2526
`
2627

@@ -555,7 +556,6 @@ export class DBClient {
555556
// Get deals
556557
const cids = uploads?.map((u) => u.content.cid)
557558
const deals = await this.getDealsForCids(cids)
558-
559559
return {
560560
count,
561561
uploads: uploads?.map((u) => ({

packages/db/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"license": "(Apache-2.0 OR MIT)",
2323
"dependencies": {
2424
"@supabase/postgrest-js": "^0.37.0",
25+
"multiformats": "^13.0.0",
2526
"p-retry": "^4.6.1"
2627
},
2728
"devDependencies": {

packages/db/postgres/functions.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ DROP FUNCTION IF EXISTS user_used_storage;
1010
DROP FUNCTION IF EXISTS user_auth_keys_list;
1111
DROP FUNCTION IF EXISTS find_deals_by_content_cids;
1212
DROP FUNCTION IF EXISTS upsert_user;
13+
DROP TYPE IF EXISTS stored_bytes;
1314

1415
-- transform a JSON array property into an array of SQL text elements
1516
CREATE OR REPLACE FUNCTION json_arr_to_text_arr(_json json)

packages/db/postgres/reset.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,18 @@ DROP TABLE IF EXISTS pin_sync_request;
1111
DROP TABLE IF EXISTS psa_pin_request;
1212
DROP TABLE IF EXISTS content;
1313
DROP TABLE IF EXISTS backup;
14+
DROP TABLE IF EXISTS auth_key_history;
1415
DROP TABLE IF EXISTS auth_key;
15-
DROP TABLE IF EXISTS public.user;
1616
DROP TABLE IF EXISTS user_tag;
1717
DROP TABLE IF EXISTS user_tag_proposal;
18+
DROP TABLE IF EXISTS email_history;
19+
DROP TABLE IF EXISTS user_customer;
20+
DROP TABLE IF EXISTS agreement;
21+
DROP TABLE IF EXISTS public.user;
1822
DROP TABLE IF EXISTS terms_of_service;
1923

24+
DROP TYPE IF EXISTS stored_bytes;
25+
2026
DROP SCHEMA IF EXISTS cargo CASCADE;
2127
DROP SERVER IF EXISTS dag_cargo_server CASCADE;
2228
DROP MATERIALIZED VIEW IF EXISTS public.aggregate_entry CASCADE;

packages/db/postgres/tables.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ CREATE INDEX IF NOT EXISTS pin_sync_request_inserted_at_idx ON pin_sync_request
300300

301301
-- Setting search_path to public scope for uuid function(s)
302302
SET search_path TO public;
303+
DROP TABLE IF EXISTS psa_pin_request;
303304
DROP extension IF EXISTS "uuid-ossp";
304305
CREATE extension "uuid-ossp" SCHEMA public;
305306

@@ -356,6 +357,8 @@ CREATE TABLE IF NOT EXISTS email_history
356357
sent_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
357358
);
358359

360+
361+
DROP VIEW IF EXISTS admin_search;
359362
CREATE VIEW admin_search as
360363
select
361364
u.id::text as user_id,

0 commit comments

Comments
 (0)