Skip to content

Commit

Permalink
more modules & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
radityaharya authored May 1, 2024
1 parent 3730847 commit 4dfec18
Show file tree
Hide file tree
Showing 19 changed files with 775 additions and 222 deletions.
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"noAssignInExpressions": "off"
},
"correctness": {
"noUndeclaredVariables": "off"
"noUndeclaredVariables": "off",
"useExhaustiveDependencies":"warn"
}
}
},
Expand Down
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@sentry/nextjs": "^7.112.2",
"@t3-oss/env-nextjs": "^0.10.0",
"@tanstack/react-table": "^8.16.0",
"@types/lodash": "^4.17.0",
"@types/spotify-api": "^0.0.25",
"@xyflow/react": "^12.0.0-next.14",
"bullmq": "^5.7.2",
Expand All @@ -55,6 +56,7 @@
"date-fns": "^3.6.0",
"drizzle-orm": "latest",
"ioredis": "^5.4.1",
"lodash": "^4.17.21",
"lucide-react": "^0.371.0",
"million": "^3.0.6",
"next": "^14.2.3",
Expand All @@ -79,7 +81,7 @@
"tailwindcss-animate": "^1.0.7",
"uuid": "^9.0.1",
"validator": "^13.11.0",
"zod": "^3.22.4",
"zod": "^3.23.5",
"zustand": "^4.5.2"
},
"devDependencies": {
Expand Down
10 changes: 0 additions & 10 deletions src/app/api/workflow/[id]/run/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ export async function POST(
}
const id = params.id;

const workers = await db.query.workerPool.findMany({});

if (workers.length === 0) {
log.error("No workers available");
return NextResponse.json(
{ error: "No workers available" },
{ status: 500 },
);
}

const workflow = await db.query.workflowJobs.findFirst({
where: (workflowJobs, { eq }) => eq(workflowJobs.id, id),
});
Expand Down
32 changes: 31 additions & 1 deletion src/app/workflow/Flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ import { useShallow } from "zustand/react/shallow";

import Alternate from "@nodes/Combiner/Alternate";
import Push from "@nodes/Combiner/Push";
import RandomStream from "@nodes/Combiner/RandomStream";

import LikedTracks from "@nodes/Library/LikedTracks";
import Playlist from "@nodes/Library/Playlist";
import SaveAsAppend from "@nodes/Library/SaveAsAppend";
import SaveAsNew from "@nodes/Library/SaveAsNew";
import SaveAsReplace from "@nodes/Library/SaveAsReplace";
import AlbumTracks from "@nodes/Library/AlbumTracks";
import Last from "@nodes/Selectors/Last";
import ArtistsTopTracks from "@nodes/Library/ArtistsTopTracks";

import DedupeArtists from "@nodes/Filter/DedupeArtists";
import DedupeTracks from "@nodes/Filter/DedupeTracks";
Expand All @@ -34,11 +38,12 @@ import RemoveMatch from "@nodes/Filter/RemoveMatch";
import Shuffle from "@nodes/Order/Shuffle";
import Sort from "@nodes/Order/Sort";
import SortPopularity from "@nodes/Order/SortPopularity";
import Reverse from "@nodes/Order/Reverse";
import SeparateArtists from "@nodes/Order/SeparateArtists";

import AllButFirst from "@nodes/Selectors/AllButFirst";
import AllButLast from "@nodes/Selectors/AllButLast";
import First from "@nodes/Selectors/First";
import Last from "@nodes/Selectors/Last";
import Recommend from "@nodes/Selectors/Recommend";

import { Button } from "@/components/ui/button";
Expand Down Expand Up @@ -71,6 +76,11 @@ export const Nodes = {
node: Push,
description: "Append tracks of sources sequentially",
},
"Combiner.randomStream": {
title: "Random Stream",
node: RandomStream,
description: "Randomly select tracks from sources",
},
"Filter.dedupeTracks": {
title: "Dedup Tracks",
node: DedupeTracks,
Expand Down Expand Up @@ -117,11 +127,31 @@ export const Nodes = {
description:
"Saves workflow output to an existing playlist by replacing all tracks",
},
"Library.albumTracks": {
title: "Album",
node: AlbumTracks,
description: "Album source",
},
"Library.artistsTopTracks": {
title: "Artists Top Tracks",
node: ArtistsTopTracks,
description: "Top tracks of artists",
},
"Order.shuffle": {
title: "Shuffle",
node: Shuffle,
description: "Randomly shuffle tracks",
},
"Order.reverse": {
title: "Reverse",
node: Reverse,
description: "Reverse the order of tracks",
},
"Order.separateArtists": {
title: "Separate Artists",
node: SeparateArtists,
description: "Sort tracks based on artists",
},
"Order.sort": {
title: "Sort",
node: Sort,
Expand Down
56 changes: 56 additions & 0 deletions src/components/nodes/Combiner/RandomStream.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-explicit-any */
"use client";

import { Position } from "@xyflow/react";
import NodeHandle from "../Primitives/NodeHandle";

import React from "react";
import { Separator } from "~/components/ui/separator";
import useBasicNodeState from "~/hooks/useBasicNodeState";
import { CardWithHeader } from "../Primitives/Card";
import Debug from "../Primitives/Debug";
import { SourceList } from "../Primitives/SourceList";

type PlaylistProps = {
id: string;
data: any;
};

const RandomStream: React.FC<PlaylistProps> = ({ id, data }) => {
const { state, isValid, targetConnections, sourceConnections } =
useBasicNodeState(id);

return (
<CardWithHeader
title={`Push`}
id={id}
type="Combiner"
status={isValid === null ? "loading" : isValid ? "success" : "error"}
info="Selects a random stream from connected sources"
>
<NodeHandle
type="source"
position={Position.Right}
style={{ background: "#555" }}
/>
<NodeHandle
type="target"
position={Position.Left}
style={{ background: "#555" }}
/>
<div className="flex flex-col gap-4">
<SourceList state={state} isValid={isValid} operationType="Selecting from" />
<Separator />
<Debug
id={id}
isValid={isValid}
TargetConnections={targetConnections}
SourceConnections={sourceConnections}
/>
</div>
</CardWithHeader>
);
};

export default RandomStream;
59 changes: 59 additions & 0 deletions src/components/nodes/Library/AlbumTracks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from "react";
import * as z from "zod";
import InputPrimitive from "../Primitives/Input";
import NodeBuilder from "../Primitives/NodeBuilder";

const formSchema = z.object({
albumId: z.string().min(1, {
message: "Album ID is required.",
}),
limit: z.number().default(10),
offset: z.number().default(0),
});

const AlbumTracks: React.FC = ({ id, data }: any) => {
return (
<NodeBuilder
id={id}
data={data}
title="Album Tracks"
type="Library"
info="Get tracks from an album"
formSchema={formSchema}
handleConnectionType="both"
formFields={({ form, register }) => (
<>
<InputPrimitive
control={form.control}
name="albumId"
inputType={"text"}
label={"Album ID"}
register={register}
placeholder={"Album ID"}
description={"The ID of the album to sort by popularity"}
/>
<InputPrimitive
control={form.control}
name="limit"
inputType={"number"}
label={"Limit"}
register={register}
placeholder={"10"}
description={"The number of tracks to return"}
/>
<InputPrimitive
control={form.control}
name="offset"
inputType={"number"}
label={"Offset"}
register={register}
placeholder={"0"}
description={"The offset to start at"}
/>
</>
)}
/>
);
};

export default AlbumTracks;
59 changes: 59 additions & 0 deletions src/components/nodes/Library/ArtistsTopTracks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from "react";
import * as z from "zod";
import InputPrimitive from "../Primitives/Input";
import NodeBuilder from "../Primitives/NodeBuilder";

const formSchema = z.object({
artistsId: z.string().min(1, {
message: "Album ID is required.",
}),
limit: z.number().default(10),
offset: z.number().default(0),
});

const ArtistsTopTracks: React.FC = ({ id, data }: any) => {
return (
<NodeBuilder
id={id}
data={data}
title="Artists Top Tracks"
type="Library"
info="Get tracks from an artists top tracks."
formSchema={formSchema}
handleConnectionType="both"
formFields={({ form, register }) => (
<>
<InputPrimitive
control={form.control}
name="artistId"
inputType={"text"}
label={"Artist ID"}
register={register}
placeholder={"Artist ID"}
description={"The ID of the artist to get top tracks for"}
/>
<InputPrimitive
control={form.control}
name="limit"
inputType={"number"}
label={"Limit"}
register={register}
placeholder={"10"}
description={"The number of tracks to return"}
/>
<InputPrimitive
control={form.control}
name="offset"
inputType={"number"}
label={"Offset"}
register={register}
placeholder={"0"}
description={"The offset to start at"}
/>
</>
)}
/>
);
};

export default ArtistsTopTracks;
5 changes: 0 additions & 5 deletions src/components/nodes/Library/Playlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ const PlaylistComponent: React.FC<PlaylistProps> = ({ id, data }) => {
position={Position.Right}
style={{ background: "#555" }}
/>
<NodeHandle
type="target"
position={Position.Left}
style={{ background: "#555" }}
/>
<Form {...form!}>
<form onSubmit={form!.handleSubmit((data) => console.info(data))}>
<div className="flex flex-col gap-4">
Expand Down
18 changes: 18 additions & 0 deletions src/components/nodes/Order/Reverse.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from "react";
import NodeBuilder from "../Primitives/NodeBuilder";

const Reverse: React.FC = ({ id, data }: any) => {

return (
<NodeBuilder
id={id}
data={data}
title="Reverse"
type="Order"
info="Reverses the order of tracks"
handleConnectionType="both"
/>
);
};

export default Reverse;
Loading

0 comments on commit 4dfec18

Please sign in to comment.