-
-
Notifications
You must be signed in to change notification settings - Fork 958
feat: Add support for user uploaded files #2100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
d005690
8aa5ef5
fa92102
01d8142
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,15 +101,23 @@ export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { | |
| prefetch={false} | ||
| > | ||
| {ASSET_TYPE_TO_ICON[asset.assetType]} | ||
| <p>{humanFriendlyNameForAssertType(asset.assetType)}</p> | ||
| <p> | ||
| {asset.assetType === "userUploaded" && asset.fileName | ||
| ? asset.fileName | ||
| : humanFriendlyNameForAssertType(asset.assetType)} | ||
| </p> | ||
| </Link> | ||
| <div className="flex gap-2"> | ||
| <Link | ||
| title="Download" | ||
| target="_blank" | ||
| href={getAssetUrl(asset.id)} | ||
| className="flex items-center gap-1" | ||
| download={humanFriendlyNameForAssertType(asset.assetType)} | ||
| download={ | ||
| asset.assetType === "userUploaded" && asset.fileName | ||
| ? asset.fileName | ||
| : humanFriendlyNameForAssertType(asset.assetType) | ||
| } | ||
| prefetch={false} | ||
| > | ||
| <Download className="size-4" /> | ||
|
|
@@ -118,7 +126,11 @@ export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { | |
| <FilePickerButton | ||
| title="Replace" | ||
| loading={isReplacing} | ||
| accept=".jgp,.JPG,.jpeg,.png,.webp" | ||
| accept={ | ||
| asset.assetType === "userUploaded" | ||
| ? undefined | ||
| : ".jgp,.JPG,.jpeg,.png,.webp" | ||
| } | ||
| multiple={false} | ||
| variant="none" | ||
| size="none" | ||
|
|
@@ -194,6 +206,30 @@ export default function AttachmentBox({ bookmark }: { bookmark: ZBookmark }) { | |
| Attach a Banner | ||
| </FilePickerButton> | ||
| )} | ||
| <FilePickerButton | ||
| title="Upload File" | ||
| loading={isAttaching} | ||
| multiple={false} | ||
| variant="ghost" | ||
| size="none" | ||
| className="flex w-full items-center justify-center gap-2" | ||
| onFileSelect={(file) => | ||
| uploadAsset(file, { | ||
| onSuccess: (resp) => { | ||
| attachAsset({ | ||
|
Comment on lines
+212
to
+216
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new "Upload File" button allows selecting any file, but the upload endpoint ( Useful? React with 👍 / 👎. |
||
| bookmarkId: bookmark.id, | ||
| asset: { | ||
| id: resp.assetId, | ||
| assetType: "userUploaded", | ||
| }, | ||
| }); | ||
| }, | ||
| }) | ||
| } | ||
| > | ||
| <Plus className="size-4" /> | ||
| Upload File | ||
| </FilePickerButton> | ||
| </CollapsibleContent> | ||
| </Collapsible> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,6 +228,7 @@ export const enum AssetTypes { | |
| LINK_VIDEO = "linkVideo", | ||
| LINK_HTML_CONTENT = "linkHtmlContent", | ||
| BOOKMARK_ASSET = "bookmarkAsset", | ||
| USER_UPLOADED = "userUploaded", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainLGTM: USER_UPLOADED asset type properly added to schema. The new asset type is correctly declared in both the enum definition and the table constraint list, following the existing pattern for other asset types. Please ensure a database migration has been created to support the new USER_UPLOADED asset type in the schema. Run the following script to check for recent migrations: Also applies to: 250-250 🏁 Script executed: #!/bin/bash
# Check for recent migration files that might include the USER_UPLOADED asset type
fd -e sql -e ts migration packages/db | head -20Length of output: 0 🏁 Script executed: #!/bin/bash
# Explore packages/db directory structure
echo "=== Directory structure of packages/db ==="
find packages/db -type f -name "*migration*" -o -name "*migrate*" 2>/dev/null | head -20
echo -e "\n=== All files in packages/db ==="
find packages/db -type f | head -30
echo -e "\n=== Search for USER_UPLOADED in packages/db ==="
rg -n "USER_UPLOADED" packages/db/Length of output: 1600 🏁 Script executed: #!/bin/bash
# Check the schema.ts file around the lines mentioned
echo "=== Content of schema.ts around lines 231 and 250 ==="
sed -n '225,260p' packages/db/schema.tsLength of output: 1226 🏁 Script executed: #!/bin/bash
# Search entire codebase for migration-related patterns
echo "=== Search for migration files/folders ==="
find . -type d -name "*migrat*" 2>/dev/null | grep -v node_modules
echo -e "\n=== Search for USER_UPLOADED in entire codebase ==="
rg -n "USER_UPLOADED" --type ts --type sql 2>/dev/null | head -30Length of output: 434 Length of output: 715 🏁 Script executed: #!/bin/bash
# Search for references to USER_UPLOADED to understand scope
echo "=== All references to USER_UPLOADED in codebase ==="
rg -n "USER_UPLOADED" --type ts --type sql
echo -e "\n=== Check packages/trpc/lib/attachments.ts context ==="
sed -n '15,45p' packages/trpc/lib/attachments.tsLength of output: 1497 🏁 Script executed: #!/bin/bash
# Verify schema.ts has the complete AssetTypes enum
echo "=== Complete AssetTypes enum ==="
rg -A 15 "enum AssetTypes" packages/db/schema.tsLength of output: 501 Missing database migration for USER_UPLOADED asset type. The schema.ts changes are correct, but there is no corresponding migration file in packages/db/drizzle/. Since USER_UPLOADED is already referenced in packages/trpc/lib/attachments.ts (lines 19, 37), the database schema must be updated to support this new enum value. A migration file needs to be generated to add the USER_UPLOADED enum variant to the assets table's assetType constraint. 🤖 Prompt for AI Agents |
||
| UNKNOWN = "unknown", | ||
| } | ||
|
|
||
|
|
@@ -246,6 +247,7 @@ export const assets = sqliteTable( | |
| AssetTypes.LINK_VIDEO, | ||
| AssetTypes.LINK_HTML_CONTENT, | ||
| AssetTypes.BOOKMARK_ASSET, | ||
| AssetTypes.USER_UPLOADED, | ||
| AssetTypes.UNKNOWN, | ||
| ], | ||
| }).notNull(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix typo in file extensions filter.
The accept filter has a typo: ".jgp" should be ".jpg". Note this typo also exists on line 186 in the "Attach a Banner" button.
Apply this diff to fix the typo in both locations:
accept={ asset.assetType === "userUploaded" ? undefined - : ".jgp,.JPG,.jpeg,.png,.webp" + : ".jpg,.JPG,.jpeg,.png,.webp" }Also fix line 186:
loading={isAttaching} - accept=".jgp,.JPG,.jpeg,.png,.webp" + accept=".jpg,.JPG,.jpeg,.png,.webp" multiple={false}📝 Committable suggestion
🤖 Prompt for AI Agents