stacker.news/api/resolvers/index.js

57 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-03-25 19:29:24 +00:00
import user from './user'
import message from './message'
2021-04-12 18:05:09 +00:00
import item from './item'
2021-04-30 21:42:51 +00:00
import wallet from './wallet'
2021-06-27 03:09:39 +00:00
import lnurl from './lnurl'
2021-08-17 18:15:24 +00:00
import notifications from './notifications'
2021-10-12 23:49:04 +00:00
import invite from './invite'
2022-02-17 17:23:43 +00:00
import sub from './sub'
2022-05-12 18:44:21 +00:00
import upload from './upload'
2023-05-18 23:41:56 +00:00
import growth from './growth'
2022-10-20 22:44:44 +00:00
import search from './search'
2022-12-08 00:04:02 +00:00
import rewards from './rewards'
2022-12-19 22:27:52 +00:00
import referrals from './referrals'
import price from './price'
2023-07-27 00:18:42 +00:00
import { GraphQLJSONObject as JSONObject } from 'graphql-type-json'
2023-06-20 01:26:34 +00:00
import admin from './admin'
import blockHeight from './blockHeight'
Image uploads (#576) * Add icon to add images * Open file explorer to select image * Upload images to S3 on selection * Show uploaded images below text input * Link and remove image * Fetch unsubmitted images from database * Mark S3 images as submitted in imgproxy job * Add margin-top * Mark images as submitted on client after successful mutation * Also delete objects in S3 * Allow items to have multiple uploads linked * Overwrite old avatar * Add fees for presigned URLs * Use Github style upload * removed upfront fees * removed images provider since we no longer need to keep track of unsubmitted images on the client * removed User.images resolver * removed deleteImage mutation * use Github style upload where it shows ![Uploading <filename>...]() first and then replaces that with ![<filename>](<url>) after successful upload * Add Upload.paid boolean column One item can have multiple images linked to it, but an image can also be used in multiple items (many-to-many relation). Since we don't really care to which item an image is linked and vice versa, we just use a boolean column to mark if an image was already paid for. This makes fee calculation easier since no JOINs are required. * Add image fees during item creation/update * we calculate image fees during item creation and update now * function imageFees returns queries which deduct fees from user and mark images as paid + fees * queries need to be run inside same transaction as item creation/update * Allow anons to get presigned URLs * Add comments regarding avatar upload * Use megabytes in error message * Remove unnecessary avatar check during image fees calculation * Show image fees in frontend * Also update image fees on blur This makes sure that the images fees reflect the current state. For example, if an image was removed. We could also add debounced requests. * Show amount of unpaid images in receipt * Fix fees in sats deducted from msats * Fix algebraic order of fees Spam fees must come immediately after the base fee since it multiplies the base fee. * Fix image fees in edit receipt * Fix stale fees shown If we pay for an image and then want to edit the comment, the cache might return stale date; suggesting we didn't pay for the existing image yet. * Add 0 base fee in edit receipt * Remove 's' from 'image fees' in receipts * Remove unnecessary async * Remove 'Uploading <name>...' from text input on error * Support upload of multiple files at once * Add schedule to delete unused images * Fix image fee display in receipts * Use Drag and Drop API for image upload * Remove dragOver style on drop * Increase max upload size to 10MB to allow HQ camera pictures * Fix free upload quota * Fix stale image fees served * Fix bad image fee return statements * Fix multiplication with feesPerImage * Fix NULL returned for size24h, sizeNow * Remove unnecessary text field in query * refactor: Unify <ImageUpload> and <Upload> component * Add avatar cache busting using random query param * Calculate image fee info in postgres function * we now calculate image fee info in a postgres function which is much cleaner * we use this function inside `create_item` and `update_item`: image fees are now deducted in the same transaction as creating/updating the item! * reversed changes in `serializeInvoiceable` * Fix line break in receipt * Update upload limits * Add comment about `e.target.value = null` * Use debounce instead of onBlur to update image fees info * Fix invoice amount * Refactor avatar upload control flow * Update image fees in onChange * Fix rescheduling of other jobs * also update schedule from every minute to every hour * Add image fees in calling context * keep item ids on uploads * Fix incompatible onSubmit signature * Revert "keep item ids on uploads" This reverts commit 4688962abcd54fdc5850109372a7ad054cf9b2e4. * many2many item uploads * pretty subdomain for images * handle upload conditions for profile images and job logos --------- Co-authored-by: ekzyis <ek@ekzyis.com> Co-authored-by: ekzyis <ek@stacker.news>
2023-11-06 20:53:33 +00:00
import image from './image'
2023-07-27 00:18:42 +00:00
import { GraphQLScalarType, Kind } from 'graphql'
2023-11-22 16:30:43 +00:00
import { createIntScalar } from 'graphql-scalar'
2023-07-27 00:18:42 +00:00
const date = new GraphQLScalarType({
name: 'Date',
description: 'Date custom scalar type',
serialize (value) {
if (value instanceof Date) {
return value.toISOString() // Convert outgoing Date to string for JSON
} else if (typeof value === 'string') {
return value
}
throw Error('GraphQL Date Scalar serializer expected a `Date` object got `' + typeof value + '` ' + value)
},
parseValue (value) {
if (typeof value === 'string') {
return new Date(value) // Convert incoming string to Date
}
throw new Error('GraphQL Date Scalar parser expected a `string`')
},
parseLiteral (ast) {
if (ast.kind === Kind.STRING) {
// Convert hard-coded AST string to integer and then to Date
return new Date(ast.value)
}
// Invalid hard-coded value (not an integer)
return null
}
})
2021-03-25 19:29:24 +00:00
2023-11-22 16:30:43 +00:00
const limit = createIntScalar({
name: 'Limit',
description: 'Limit custom scalar type',
maximum: 1000
})
2022-05-12 18:44:21 +00:00
export default [user, item, message, wallet, lnurl, notifications, invite, sub,
2023-11-22 16:30:43 +00:00
upload, search, growth, rewards, referrals, price, admin, blockHeight, image, { JSONObject }, { Date: date }, { Limit: limit }]