Skip to content

Commit

Permalink
Add bot badge to items created with API key (#1209)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis authored May 30, 2024
1 parent 050122c commit d2a981c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/resolvers/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,9 @@ export const createItem = async (parent, { forward, options, ...item }, { me, mo
item.url = removeTracking(item.url)
}

// mark item as created with API key
item.apiKey = me?.apiKey

const uploadIds = uploadIdsFromText(item.text, { models })
const { totalFees: imgFees } = await imageFeesInfo(uploadIds, { models, me })

Expand Down Expand Up @@ -1433,7 +1436,7 @@ export const SELECT =
"Item".ncomments, "Item"."commentMsats", "Item"."lastCommentAt", "Item"."weightedVotes",
"Item"."weightedDownVotes", "Item".freebie, "Item".bio, "Item"."otsHash", "Item"."bountyPaidTo",
ltree2text("Item"."path") AS "path", "Item"."weightedComments", "Item"."imgproxyUrls", "Item".outlawed,
"Item"."pollExpiresAt"`
"Item"."pollExpiresAt", "Item"."apiKey"`

function topOrderByWeightedSats (me, models) {
return `ORDER BY ${orderByNumerator(models)} DESC NULLS LAST, "Item".id DESC`
Expand Down
1 change: 1 addition & 0 deletions api/typeDefs/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default gql`
forwards: [ItemForward]
imgproxyUrls: JSONObject
rel: String
apiKey: Boolean
}
input ItemForwardInput {
Expand Down
3 changes: 3 additions & 0 deletions components/item-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ export default function ItemInfo ({
{' '}<Badge className={styles.newComment} bg={null}>freebie</Badge>
</Link>
)}
{(item.apiKey &&
<>{' '}<Badge className={styles.newComment} bg={null}>bot</Badge></>
)}
{extraBadges}
{canEdit && !item.deletedAt &&
<>
Expand Down
1 change: 1 addition & 0 deletions fragments/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const COMMENT_FIELDS = gql`
ncomments
imgproxyUrls
rel
apiKey
}
`

Expand Down
1 change: 1 addition & 0 deletions fragments/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const ITEM_FIELDS = gql`
mine
imgproxyUrls
rel
apiKey
}`

export const ITEM_FULL_FIELDS = gql`
Expand Down
2 changes: 2 additions & 0 deletions prisma/migrations/20240529074650_item_bot_badge/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Item" ADD COLUMN "apiKey" BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ model Item {
ItemUpload ItemUpload[]
uploadId Int?
outlawed Boolean @default(false)
apiKey Boolean @default(false)
pollExpiresAt DateTime?
Ancestors Reply[] @relation("AncestorReplyItem")
Replies Reply[]
Expand Down

0 comments on commit d2a981c

Please sign in to comment.