Skip to content

Commit

Permalink
Add ddex_app field for ddex tracks/playlists to discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
michellebrier committed Feb 28, 2024
1 parent 3e1b544 commit 5a54445
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/common/src/models/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export type CollectionMetadata = {
offline?: OfflineCollectionMetadata
local?: boolean
release_date?: string
ddex_app?: string | null
}

export type CollectionDownloadReason = { is_from_favorites: boolean }
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/models/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export type TrackMetadata = {
orig_filename: Nullable<string>
is_downloadable: boolean
is_original_available: boolean
ddex_app?: Nullable<string>

// Optional Fields
is_playlist_upload?: boolean
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/services/audius-api-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export type APITrack = {
orig_filename: Nullable<string>
is_downloadable: boolean
is_original_available: boolean
ddex_app: Nullable<string>
}

export type APISearchTrack = Omit<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
begin;

alter table tracks add column if not exists ddex_app varchar;
alter table playlists add column if not exists ddex_app varchar;

commit;
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export interface PlaylistRow {
txhash?: string
upc?: string | null
updated_at: Date
ddex_app?: string | null
}
export interface PlayRow {
city?: string | null
Expand Down Expand Up @@ -639,6 +640,7 @@ export interface TrackRow {
track_segments: any
txhash?: string
updated_at: Date
ddex_app?: string | null
}
export interface TrendingParamRow {
genre?: string | null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ export type Playlists = {
slot: number | null;
metadata_multihash: string | null;
is_image_autogenerated: boolean;
ddex_app: string | null;
};

export type Plays = {
Expand Down Expand Up @@ -988,6 +989,7 @@ export type Tracks = {
is_original_available: boolean;
orig_file_cid: string | null;
orig_filename: string | null;
ddex_app: string | null;
};

export type TrendingResults = {
Expand Down
1 change: 1 addition & 0 deletions packages/discovery-provider/src/api/v1/models/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"favorite_count": fields.Integer(required=True),
"total_play_count": fields.Integer(required=True),
"user": fields.Nested(user_model, required=True),
"ddex_app": fields.String(allow_null=True)
},
)

Expand Down
1 change: 1 addition & 0 deletions packages/discovery-provider/src/api/v1/models/tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"play_count": fields.Integer(required=True),
"permalink": fields.String,
"is_streamable": fields.Boolean,
"ddex_app": fields.String(allow_null=True),
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Playlist(Base, RepresentableMixin):
upc = Column(String)
updated_at = Column(DateTime, nullable=False)
playlist_image_sizes_multihash = Column(String)
ddex_app = Column(String)
is_image_autogenerated = Column(
Boolean, nullable=False, server_default=text("false")
)
Expand Down
1 change: 1 addition & 0 deletions packages/discovery-provider/src/models/tracks/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Track(Base, RepresentableMixin):
download = Column(JSONB())
is_scheduled_release = Column(Boolean, nullable=False, server_default=text("false"))
is_unlisted = Column(Boolean, nullable=False, server_default=text("false"))
ddex_app = Column(String)
field_visibility = Column(JSONB(True))
route_id = Column(String)
stem_of = Column(JSONB(True))
Expand Down
4 changes: 4 additions & 0 deletions packages/discovery-provider/src/schemas/playlist_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
"is_image_autogenerated": {
"type": "boolean",
"default": false
},
"ddex_app": {
"type": ["string", "null"],
"default": null
}
},
"required": [],
Expand Down
9 changes: 8 additions & 1 deletion packages/discovery-provider/src/schemas/track_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@
],
"default": null
},
"ddex_app": {
"type": [
"string",
"null"
],
"default": null
},
"track_segments": {
"type": "array",
"minItems": 0,
Expand Down Expand Up @@ -602,4 +609,4 @@
]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
ManageEntityParameters,
copy_record,
validate_signer,
get_ddex_apps,
)
from src.tasks.metadata import immutable_playlist_fields
from src.tasks.task_helpers import generate_slug_and_collision_id
Expand Down Expand Up @@ -276,6 +277,11 @@ def create_playlist(params: ManageEntityParameters):
tracks = params.metadata["playlist_contents"].get("track_ids", [])
tracks_with_index_time = []
last_added_to = None

ddex_app = None
if params.signer in get_ddex_apps():
ddex_app = params.signer

for track in tracks:
if "track" not in track or "time" not in track:
raise IndexingValidationError(
Expand Down Expand Up @@ -312,6 +318,7 @@ def create_playlist(params: ManageEntityParameters):
last_added_to=last_added_to,
is_current=False,
is_delete=False,
ddex_app=ddex_app,
)

update_playlist_routes_table(params, playlist_record, True)
Expand All @@ -335,6 +342,12 @@ def dispatch_challenge_playlist_upload(
)


def validate_update_ddex_playlist(params: ManageEntityParameters, playlist_record):
if playlist_record.ddex_app:
if playlist_record.ddex_app != params.signer or params.signer not in get_ddex_apps():
raise IndexingValidationError(f"Signer {params.signer} does not have permission to {params.action} DDEX playlist {playlist_record.playlist_id}")


def update_playlist(params: ManageEntityParameters):
validate_playlist_tx(params)
# TODO ignore updates on deleted playlists?
Expand All @@ -346,6 +359,8 @@ def update_playlist(params: ManageEntityParameters):
): # override with last updated playlist is in this block
existing_playlist = params.new_records["Playlist"][playlist_id][-1]

validate_update_ddex_playlist(params, existing_playlist)

playlist_record = copy_record(
existing_playlist,
params.block_number,
Expand Down Expand Up @@ -375,6 +390,8 @@ def delete_playlist(params: ManageEntityParameters):
# override with last updated playlist is in this block
existing_playlist = params.new_records["Playlist"][params.entity_id][-1]

validate_update_ddex_playlist(params, existing_playlist)

deleted_playlist = copy_record(
existing_playlist,
params.block_number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ManageEntityParameters,
copy_record,
validate_signer,
get_ddex_apps,
)
from src.tasks.metadata import immutable_track_fields
from src.tasks.task_helpers import generate_slug_and_collision_id
Expand Down Expand Up @@ -462,6 +463,9 @@ def create_track(params: ManageEntityParameters):
is_delete=False,
)

if params.signer in get_ddex_apps():
track_record.ddex_app = params.signer

update_track_routes_table(
params, track_record, params.metadata, params.pending_track_routes
)
Expand All @@ -483,6 +487,12 @@ def create_track(params: ManageEntityParameters):
params.add_record(track_id, track_record)


def validate_update_ddex_track(params: ManageEntityParameters, track_record):
if track_record.ddex_app:
if track_record.ddex_app != params.signer or params.signer not in get_ddex_apps():
raise IndexingValidationError(f"Signer {params.signer} does not have permission to {params.action} DDEX track {track_record.track_id}")


def update_track(params: ManageEntityParameters):
handle = get_handle(params)
validate_track_tx(params)
Expand All @@ -494,6 +504,8 @@ def update_track(params: ManageEntityParameters):
): # override with last updated track is in this block
existing_track = params.new_records["Track"][track_id][-1]

validate_update_ddex_track(params, existing_track)

track_record = copy_record(
existing_track,
params.block_number,
Expand Down Expand Up @@ -527,6 +539,8 @@ def delete_track(params: ManageEntityParameters):
# override with last updated playlist is in this block
existing_track = params.new_records["Track"][params.entity_id][-1]

validate_update_ddex_track(params, existing_track)

deleted_track = copy_record(
existing_track,
params.block_number,
Expand Down
6 changes: 6 additions & 0 deletions packages/discovery-provider/src/tasks/entity_manager/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from datetime import datetime
from enum import Enum
from typing import Dict, List, Literal, Set, Tuple, TypedDict, Union
Expand Down Expand Up @@ -479,3 +480,8 @@ def get_address_from_signature(signature):
message_hash, signature=signature["signature"]
)
return app_address.lower()


def get_ddex_apps():
# TODO read from a table in the db after implementing UI to register a DDEX node
return os.getenv("audius_ddex_apps").split(",")
4 changes: 4 additions & 0 deletions packages/discovery-provider/src/tasks/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TrackMetadata(TypedDict):
download_conditions: Optional[Any]
is_playlist_upload: Optional[bool]
ai_attribution_user_id: Optional[int]
ddex_app: Optional[str]


track_metadata_format: TrackMetadata = {
Expand Down Expand Up @@ -120,6 +121,7 @@ class TrackMetadata(TypedDict):
"download_conditions": None,
"is_playlist_upload": False,
"ai_attribution_user_id": None,
"ddex_app": None,
}

# Required format for user metadata retrieved from the content system
Expand Down Expand Up @@ -153,6 +155,7 @@ class PlaylistMetadata(TypedDict):
is_album: Optional[bool]
is_private: Optional[bool]
is_image_autogenerated: Optional[bool]
ddex_app: Optional[str],


playlist_metadata_format: PlaylistMetadata = {
Expand All @@ -164,6 +167,7 @@ class PlaylistMetadata(TypedDict):
"is_album": False,
"is_private": False,
"is_image_autogenerated": None,
"ddex_app": None,
}

# Updates cannot directly modify these fields via metadata
Expand Down
2 changes: 2 additions & 0 deletions packages/es-indexer/src/types/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ export interface PlaylistRow {
'txhash': string;
'upc': string | null;
'updated_at': Date;
'ddex_app': string | null;
}
export interface PlayRow {
'city': string | null;
Expand Down Expand Up @@ -702,6 +703,7 @@ export interface TrackRow {
'track_segments': any;
'txhash': string;
'updated_at': Date;
'ddex_app': string | null;
}
export interface TrendingParamRow {
'genre': string | null;
Expand Down
4 changes: 3 additions & 1 deletion packages/libs/src/api/entityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type PlaylistParam = {
is_private: boolean
is_album: boolean
is_image_autogenerated: boolean
ddex_app?: string | null
}

/*
Expand Down Expand Up @@ -225,7 +226,8 @@ export class EntityManager extends Base {
description: playlist.description,
is_album: playlist.is_album,
is_private: playlist.is_private,
is_image_autogenerated: playlist.is_image_autogenerated
is_image_autogenerated: playlist.is_image_autogenerated,
ddex_app: playlist.ddex_app
}
this.creatorNode.validatePlaylistSchema(metadata)

Expand Down
1 change: 1 addition & 0 deletions packages/libs/src/services/creatorNode/CreatorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type PlaylistMetadata = {
is_album: boolean
is_private: boolean
is_image_autogenerated: boolean
ddex_app?: string | null
}

export type ProgressCB = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
"is_image_autogenerated": {
"type": "boolean",
"default": false
},
"ddex_app": {
"type": ["string", "null"],
"default": null
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
],
"default": null
},
"ddex_app": {
"type": [
"string",
"null"
],
"default": null
},
"track_segments": {
"type": "array",
"minItems": 0,
Expand Down Expand Up @@ -599,4 +606,4 @@
]
}
}
}
}
2 changes: 2 additions & 0 deletions packages/libs/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export type TrackMetadata = {
permalink: string
audio_upload_id: Nullable<string>
preview_start_seconds: Nullable<number>
ddex_app?: Nullable<string>

// Optional Fields
is_invalid?: boolean
Expand Down Expand Up @@ -206,4 +207,5 @@ export type CollectionMetadata = {
updated_at: string
activity_timestamp?: string
is_image_autogenerated?: boolean
ddex_app?: Nullable<string>
}
2 changes: 2 additions & 0 deletions packages/sql-ts/res/discovery-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export interface PlaylistRow {
'txhash'?: string;
'upc'?: string | null;
'updated_at': Date;
'ddex_app': string | null;
}
export interface PlayRow {
'city'?: string | null;
Expand Down Expand Up @@ -645,6 +646,7 @@ export interface TrackRow {
'track_segments': any;
'txhash'?: string;
'updated_at': Date;
'ddex_app': string | null;
}
export interface TrendingParamRow {
'genre'?: string | null;
Expand Down

0 comments on commit 5a54445

Please sign in to comment.