Skip to content

Commit

Permalink
fix: list uploads should return source cid (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Apr 26, 2022
1 parent dccf457 commit 164e06b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 58 deletions.
1 change: 1 addition & 0 deletions packages/db/db-client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export type CreateUploadOutput = {

export type UploadItem = {
id: string
sourceCid: definitions['upload']['source_cid']
type: definitions['upload']['type']
name?: definitions['upload']['name']
created?: definitions['upload']['inserted_at']
Expand Down
1 change: 1 addition & 0 deletions packages/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const uploadQuery = `
_id:id::text,
type,
name,
sourceCid:source_cid,
created:inserted_at,
updated:updated_at,
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)))
Expand Down
136 changes: 78 additions & 58 deletions packages/db/postgres/pg-rest-api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1489,13 +1489,13 @@ export interface paths {
};
};
};
"/rpc/user_auth_keys_list": {
"/rpc/upsert_pins": {
post: {
parameters: {
body: {
args: {
/** Format: bigint */
query_user_id: number;
/** Format: json */
data: string;
};
};
header: {
Expand All @@ -1509,14 +1509,11 @@ export interface paths {
};
};
};
"/rpc/create_psa_pin_request": {
"/rpc/uuid_ns_url": {
post: {
parameters: {
body: {
args: {
/** Format: json */
data: string;
};
args: { [key: string]: unknown };
};
header: {
/** Preference */
Expand All @@ -1529,14 +1526,11 @@ export interface paths {
};
};
};
"/rpc/user_used_storage": {
"/rpc/pgrst_watch": {
post: {
parameters: {
body: {
args: {
/** Format: bigint */
query_user_id: number;
};
args: { [key: string]: unknown };
};
header: {
/** Preference */
Expand All @@ -1549,14 +1543,11 @@ export interface paths {
};
};
};
"/rpc/json_arr_to_json_element_array": {
"/rpc/uuid_nil": {
post: {
parameters: {
body: {
args: {
/** Format: json */
_json: string;
};
args: { [key: string]: unknown };
};
header: {
/** Preference */
Expand All @@ -1569,14 +1560,11 @@ export interface paths {
};
};
};
"/rpc/create_key": {
"/rpc/uuid_generate_v1": {
post: {
parameters: {
body: {
args: {
/** Format: json */
data: string;
};
args: { [key: string]: unknown };
};
header: {
/** Preference */
Expand All @@ -1589,13 +1577,13 @@ export interface paths {
};
};
};
"/rpc/json_arr_to_text_arr": {
"/rpc/create_content": {
post: {
parameters: {
body: {
args: {
/** Format: json */
_json: string;
data: string;
};
};
header: {
Expand All @@ -1609,7 +1597,7 @@ export interface paths {
};
};
};
"/rpc/uuid_generate_v1mc": {
"/rpc/uuid_ns_oid": {
post: {
parameters: {
body: {
Expand All @@ -1626,11 +1614,14 @@ export interface paths {
};
};
};
"/rpc/uuid_generate_v1": {
"/rpc/user_auth_keys_list": {
post: {
parameters: {
body: {
args: { [key: string]: unknown };
args: {
/** Format: bigint */
query_user_id: number;
};
};
header: {
/** Preference */
Expand All @@ -1643,11 +1634,14 @@ export interface paths {
};
};
};
"/rpc/uuid_generate_v4": {
"/rpc/find_deals_by_content_cids": {
post: {
parameters: {
body: {
args: { [key: string]: unknown };
args: {
/** Format: text[] */
cids: string;
};
};
header: {
/** Preference */
Expand All @@ -1660,13 +1654,15 @@ export interface paths {
};
};
};
"/rpc/create_upload": {
"/rpc/uuid_generate_v5": {
post: {
parameters: {
body: {
args: {
/** Format: json */
data: string;
/** Format: uuid */
namespace: string;
/** Format: text */
name: string;
};
};
header: {
Expand Down Expand Up @@ -1700,14 +1696,11 @@ export interface paths {
};
};
};
"/rpc/find_deals_by_content_cids": {
"/rpc/uuid_ns_x500": {
post: {
parameters: {
body: {
args: {
/** Format: text[] */
cids: string;
};
args: { [key: string]: unknown };
};
header: {
/** Preference */
Expand All @@ -1720,13 +1713,13 @@ export interface paths {
};
};
};
"/rpc/publish_name_record": {
"/rpc/json_arr_to_text_arr": {
post: {
parameters: {
body: {
args: {
/** Format: json */
data: string;
_json: string;
};
};
header: {
Expand All @@ -1740,11 +1733,14 @@ export interface paths {
};
};
};
"/rpc/uuid_ns_url": {
"/rpc/publish_name_record": {
post: {
parameters: {
body: {
args: { [key: string]: unknown };
args: {
/** Format: json */
data: string;
};
};
header: {
/** Preference */
Expand All @@ -1757,15 +1753,15 @@ export interface paths {
};
};
};
"/rpc/uuid_generate_v5": {
"/rpc/uuid_generate_v3": {
post: {
parameters: {
body: {
args: {
/** Format: text */
name: string;
/** Format: uuid */
namespace: string;
/** Format: text */
name: string;
};
};
header: {
Expand All @@ -1779,7 +1775,7 @@ export interface paths {
};
};
};
"/rpc/create_content": {
"/rpc/create_key": {
post: {
parameters: {
body: {
Expand All @@ -1799,7 +1795,7 @@ export interface paths {
};
};
};
"/rpc/uuid_ns_oid": {
"/rpc/uuid_generate_v4": {
post: {
parameters: {
body: {
Expand All @@ -1816,7 +1812,7 @@ export interface paths {
};
};
};
"/rpc/pgrst_watch": {
"/rpc/uuid_ns_dns": {
post: {
parameters: {
body: {
Expand All @@ -1833,11 +1829,14 @@ export interface paths {
};
};
};
"/rpc/uuid_ns_x500": {
"/rpc/json_arr_to_json_element_array": {
post: {
parameters: {
body: {
args: { [key: string]: unknown };
args: {
/** Format: json */
_json: string;
};
};
header: {
/** Preference */
Expand All @@ -1850,11 +1849,14 @@ export interface paths {
};
};
};
"/rpc/uuid_nil": {
"/rpc/create_psa_pin_request": {
post: {
parameters: {
body: {
args: { [key: string]: unknown };
args: {
/** Format: json */
data: string;
};
};
header: {
/** Preference */
Expand All @@ -1867,7 +1869,27 @@ export interface paths {
};
};
};
"/rpc/uuid_ns_dns": {
"/rpc/user_used_storage": {
post: {
parameters: {
body: {
args: {
/** Format: bigint */
query_user_id: number;
};
};
header: {
/** Preference */
Prefer?: parameters["preferParams"];
};
};
responses: {
/** OK */
200: unknown;
};
};
};
"/rpc/uuid_generate_v1mc": {
post: {
parameters: {
body: {
Expand All @@ -1884,15 +1906,13 @@ export interface paths {
};
};
};
"/rpc/uuid_generate_v3": {
"/rpc/create_upload": {
post: {
parameters: {
body: {
args: {
/** Format: text */
name: string;
/** Format: uuid */
namespace: string;
/** Format: json */
data: string;
};
};
header: {
Expand Down
22 changes: 22 additions & 0 deletions packages/db/test/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,28 @@ describe('upload', () => {
assert.notStrictEqual(uploadWithSameCid._id, upload._id, 'a new upload was created for a new user')
})

it('lists user uploads with source cid', async () => {
const contentCid = 'bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi'
const sourceCid = 'QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'
const created = new Date().toISOString()
await client.createUpload({
user: user._id,
contentCid,
sourceCid,
authKey: authKeys[0]._id,
type,
dagSize,
name: 'ZZZZZZZZZ', // Name starting with Z for order testing
pins: [initialPinData],
backupUrls: [`https://backup.cid/${created}`],
created
})

// Default sort {inserted_at, Desc}
const userUploads = await client.listUploads(user._id)
assert.ok(userUploads.find(upload => upload.cid === sourceCid))
})

it('can list user uploads with several options', async () => {
const previousUserUploads = await client.listUploads(user._id)
assert(previousUserUploads, 'user has uploads')
Expand Down
2 changes: 2 additions & 0 deletions packages/db/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
export function normalizeUpload (upload) {
const nUpload = { ...upload }
delete nUpload.content
delete nUpload.sourceCid

return {
...nUpload,
...upload.content,
cid: upload.sourceCid, // Overwrite cid to source cid
pins: normalizePins(upload.content.pins, {
isOkStatuses: true
})
Expand Down

0 comments on commit 164e06b

Please sign in to comment.