From 0f2c5cb61ad0042883b0b43b58a9afb0600ff353 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 30 Jan 2026 19:16:01 +0800 Subject: [PATCH] feat(likecoin): remove likecoin --- .github/workflows/lambda-deploy.yml | 76 ---- src/common/enums/sqs.ts | 5 - src/connectors/__test__/likecoin.test.ts | 56 --- .../article/ipfsPublicationService.ts | 52 --- src/connectors/index.ts | 1 - src/connectors/likecoin/index.ts | 427 ------------------ src/definitions/index.d.ts | 2 - .../likecoinBatchUpdateCivicLikerCaches.ts | 104 ----- src/handlers/likecoinLike.ts | 33 -- src/handlers/likecoinUpdateCivicLikerCache.ts | 33 -- src/mutations/article/appreciateArticle.ts | 15 - src/queries/user/liker/civicLiker.ts | 17 +- src/routes/graphql.ts | 2 - 13 files changed, 2 insertions(+), 821 deletions(-) delete mode 100644 src/connectors/__test__/likecoin.test.ts delete mode 100644 src/handlers/likecoinBatchUpdateCivicLikerCaches.ts delete mode 100644 src/handlers/likecoinLike.ts delete mode 100644 src/handlers/likecoinUpdateCivicLikerCache.ts diff --git a/.github/workflows/lambda-deploy.yml b/.github/workflows/lambda-deploy.yml index b38d14b58..037574dfd 100644 --- a/.github/workflows/lambda-deploy.yml +++ b/.github/workflows/lambda-deploy.yml @@ -641,79 +641,3 @@ jobs: lambdaTimeout=10, lambdaMemorySize=256, cronExpression="rate(1 hour)" - - deploy-likecoin-update-civic-liker-cache: - needs: build-lambda-image - runs-on: ubuntu-latest - steps: - - name: Checkout Repo - uses: actions/checkout@master - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Deploy Lambda - uses: aws-actions/aws-cloudformation-github-deploy@v1 - with: - name: likecoin-update-civic-liker-cache-${{ inputs.environment }} - template: ./deployment/lambda/queuejob.yml - parameter-overrides: >- - mattersEnv=${{ env.MATTERS_ENV }}, - imageUri=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:matters-server-${{ github.SHA }}, - lambdaCMD=likecoinUpdateCivicLikerCache.handler, - lambdaTimeout=30, - lambdaMemorySize=512, - lambdaReservedConcurrency=200, - sqsArn=arn:aws:sqs:${{ secrets.AWS_REGION }}:${{ secrets.AWS_ACCOUNT_ID }}:likecoin-update-civic-liker-cache-${{ env.SQS_ENV }}, - sqsBatchSize=100, - sqsMaxBatchingWindowInSeconds=1 - - deploy-likecoin-like: - needs: build-lambda-image - runs-on: ubuntu-latest - steps: - - name: Checkout Repo - uses: actions/checkout@master - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Deploy Lambda - uses: aws-actions/aws-cloudformation-github-deploy@v1 - with: - name: likecoin-like-${{ inputs.environment }} - template: ./deployment/lambda/queuejob.yml - parameter-overrides: >- - mattersEnv=${{ env.MATTERS_ENV }}, - imageUri=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:matters-server-${{ github.SHA }}, - lambdaCMD=likecoinLike.handler, - lambdaTimeout=120, - lambdaMemorySize=512, - sqsArn=arn:aws:sqs:${{ secrets.AWS_REGION }}:${{ secrets.AWS_ACCOUNT_ID }}:likecoin-like-${{ env.SQS_ENV }}.fifo, - sqsBatchSize=10, - sqsMaxBatchingWindowInSeconds=0 - - deploy-likecoin-batch-update-civic-liker-caches: - needs: build-lambda-image - runs-on: ubuntu-latest - steps: - - name: Checkout Repo - uses: actions/checkout@master - - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Deploy Lambda - uses: aws-actions/aws-cloudformation-github-deploy@v1 - with: - name: likecoin-batch-update-civic-liker-caches-${{ inputs.environment }} - template: ./deployment/lambda/api.yml - parameter-overrides: >- - mattersEnv=${{ env.MATTERS_ENV }}, - imageUri=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:matters-server-${{ github.SHA }}, - lambdaCMD=likecoinBatchUpdateCivicLikerCaches.handler, - lambdaTimeout=20, - lambdaMemorySize=512 diff --git a/src/common/enums/sqs.ts b/src/common/enums/sqs.ts index 8ed3d3642..b77073112 100644 --- a/src/common/enums/sqs.ts +++ b/src/common/enums/sqs.ts @@ -6,11 +6,6 @@ export const QUEUE_URL = { // notification notification: environment?.awsNotificationQueueUrl, - // likecoin - likecoinLike: environment?.awsLikecoinLikeUrl, - likecoinSendPV: environment?.awsLikecoinSendPVUrl, - likecoinUpdateCivicLikerCache: environment?.awsLikecoinUpdateCivicLikerCache, - // sendmail mail: environment?.awsMailQueueUrl, expressMail: environment?.awsExpressMailQueueUrl, diff --git a/src/connectors/__test__/likecoin.test.ts b/src/connectors/__test__/likecoin.test.ts deleted file mode 100644 index f187b9c56..000000000 --- a/src/connectors/__test__/likecoin.test.ts +++ /dev/null @@ -1,56 +0,0 @@ -import type { Connections } from '#definitions/index.js' - -import { CACHE_PREFIX } from '#common/enums/index.js' -import { LikeCoin } from '../likecoin/index.js' -import { Cache } from '../cache/index.js' - -import { genConnections, closeConnections } from './utils.js' - -let connections: Connections - -beforeAll(async () => { - connections = await genConnections() -}, 30000) - -afterAll(async () => { - await closeConnections(connections) -}) - -const getCivicLikerStatus = async (likerId: string) => { - const cache = new Cache( - CACHE_PREFIX.CIVIC_LIKER, - connections.objectCacheRedis - ) - return await cache.getObject({ - keys: { id: likerId }, - getter: async () => null, - }) -} - -describe('LikeCoin', () => { - test('updateCivicLikerCaches', async () => { - const likecoin = new LikeCoin(connections) - const expire = 1 - await likecoin.updateCivicLikerCaches([]) - expect(await getCivicLikerStatus('test_liker_id_1')).toBeNull() - - await likecoin.updateCivicLikerCaches([ - { - likerId: 'not-matters-user-liker-id', - expire, - }, - ]) - expect(await getCivicLikerStatus('not-matters-user-liker-id')).toBeNull() - - await likecoin.updateCivicLikerCaches([ - { - likerId: 'test_liker_id_1', - expire, - }, - ]) - expect(await getCivicLikerStatus('test_liker_id_1')).toBe(true) - - await likecoin.updateCivicLikerCaches([]) - expect(await getCivicLikerStatus('test_liker_id_1')).toBe(true) - }) -}) diff --git a/src/connectors/article/ipfsPublicationService.ts b/src/connectors/article/ipfsPublicationService.ts index c93df11eb..ef8ca7c85 100644 --- a/src/connectors/article/ipfsPublicationService.ts +++ b/src/connectors/article/ipfsPublicationService.ts @@ -2,7 +2,6 @@ import type { Connections, ArticleVersion, Article, - UserOAuthLikeCoin, } from '#definitions/index.js' import type { Knex } from 'knex' @@ -24,7 +23,6 @@ import { PinataSDK } from 'pinata-web3' import { AtomService } from '../atomService.js' import { aws } from '../aws/index.js' -import { LikeCoin } from '../likecoin/index.js' const logger = getLogger('service-ipfs-publication') @@ -36,7 +34,6 @@ export class IPFSPublicationService { private knexRO: Knex private models: AtomService private aws: typeof aws - private likecoin: LikeCoin public constructor(connections: Connections) { this.connections = connections @@ -44,7 +41,6 @@ export class IPFSPublicationService { this.knex = connections.knex this.knexRO = connections.knexRO this.aws = aws - this.likecoin = new LikeCoin(connections) } private async initStorachaClient() { @@ -352,54 +348,6 @@ export class IPFSPublicationService { } }) - // publish to ISCN - try { - const draft = await this.models.findFirst({ - table: 'draft', - where: { articleId }, - }) - - if (article && draft && draft.iscnPublish) { - const author = await this.models.findFirst({ - table: 'user', - where: { id: draft.authorId }, - }) - - let liker: UserOAuthLikeCoin | undefined - if (author?.likerId) { - liker = await this.models.findFirst({ - table: 'user_oauth_likecoin', - where: { likerId: author.likerId }, - }) - } - - if (liker && author) { - const cosmosWallet = await this.likecoin.getCosmosWallet({ liker }) - - const { displayName, userName } = author - const iscnId = await this.likecoin.iscnPublish({ - mediaHash: `hash://sha256/${mediaHash}`, - ipfsHash: `ipfs://${dataHash}`, - cosmosWallet, - userName: `${displayName} (@${userName})`, - title: articleVersion.title, - description: articleVersion.summary, - datePublished: article.createdAt?.toISOString().substring(0, 10), - url: `https://${environment.siteDomain}/a/${article.shortHash}`, - tags: articleVersion.tags, - liker, - }) - - await this.knex('article_version') - .where({ id: articleVersionId }) - .update({ iscnId }) - } - } - } catch (err) { - console.log('Failed to publish to ISCN') - console.error(err) - } - // invalidate cache await invalidateFQC({ node: { type: NODE_TYPES.Article, id: articleId }, diff --git a/src/connectors/index.ts b/src/connectors/index.ts index ae85113ee..aaa41a955 100644 --- a/src/connectors/index.ts +++ b/src/connectors/index.ts @@ -2,7 +2,6 @@ export * from './aws/index.js' export * from './cache/index.js' export * from './cloudflare/index.js' export * from './mail/index.js' -export * from './likecoin/index.js' export * from './opensea/index.js' export * from './alchemy/index.js' export * from './passphrases/index.js' diff --git a/src/connectors/likecoin/index.ts b/src/connectors/likecoin/index.ts index a953a0fd5..3af16c27b 100644 --- a/src/connectors/likecoin/index.ts +++ b/src/connectors/likecoin/index.ts @@ -1,12 +1,9 @@ import type { UserOAuthLikeCoin, Connections } from '#definitions/index.js' -import type { Redis } from 'ioredis' import type { Knex } from 'knex' -import { CACHE_PREFIX, CACHE_TTL, QUEUE_URL } from '#common/enums/index.js' import { environment } from '#common/environment.js' import { LikerEmailExistsError, - LikerISCNPublishWithoutWalletError, LikerUserIdExistsError, OAuthTokenInvalidError, } from '#common/errors.js' @@ -14,40 +11,9 @@ import { getLogger } from '#common/logger.js' import * as Sentry from '@sentry/node' import axios, { type AxiosRequestConfig } from 'axios' import _ from 'lodash' -import { v4 } from 'uuid' - -import { aws } from '../aws/index.js' -import { Cache } from '../cache/index.js' const logger = getLogger('service-likecoin') -interface LikeData { - likerId: string - likerIp?: string - userAgent: string - authorLikerId: string - url: string - amount: number -} - -interface SendPVData { - likerId?: string - likerIp?: string - userAgent: string - authorLikerId: string - url: string -} - -interface UpdateCivicLikerCacheData { - likerId: string - userId: string - expire: (typeof CACHE_TTL)[keyof typeof CACHE_TTL] -} - -interface BaseUpdateCivicLikerCacheData { - likerId: string - expire: number -} const { likecoinApiURL, likecoinClientId, likecoinClientSecret } = environment @@ -88,15 +54,9 @@ const ENDPOINTS = { */ export class LikeCoin { private knex: Knex - private redis: Redis - private objectCacheRedis: Redis - private aws: typeof aws public constructor(connections: Connections) { this.knex = connections.knex - this.redis = connections.redis - this.objectCacheRedis = connections.objectCacheRedis - this.aws = aws } /** @@ -282,33 +242,6 @@ export class LikeCoin { return data.cosmosLIKE || data.walletLIKE } - /** - * Check if user is a civic liker - */ - public isCivicLiker = async ({ - likerId, - userId, - }: { - likerId: string - userId: string - }): Promise => { - const cache = new Cache(CACHE_PREFIX.CIVIC_LIKER, this.objectCacheRedis) - const keys = { id: likerId } - const isCivicLiker = (await cache.getObject({ - keys, - getter: async () => { - this.updateCivicLikerCache({ - likerId, - userId, - expire: CACHE_TTL.LONG, - }) - return false - }, - expire: CACHE_TTL.MEDIUM, - })) as boolean | null - return isCivicLiker ?? false - } - /** * Check if user is a civic liker */ @@ -321,138 +254,6 @@ export class LikeCoin { return _.get(res, 'data.cosmosWallet') } - /** - * Send page view to likecoin - */ - public sendPV = async (data: SendPVData) => - this.aws.sqsSendMessage({ - messageBody: data, - queueUrl: QUEUE_URL.likecoinSendPV, - }) - - /** - * Like a content. - */ - public like = async (data: LikeData) => - this.aws.sqsSendMessage({ - messageBody: data, - queueUrl: QUEUE_URL.likecoinLike, - messageGroupId: 'like', - messageDeduplicationId: v4(), - }) - - public iscnPublish = async ({ - mediaHash, - ipfsHash, - cosmosWallet, - userName, - title, - description, - datePublished, - url, - tags, - liker, - }: // likerIp, - // userAgent, - { - mediaHash: string - ipfsHash: string - cosmosWallet: string - userName: string - title: string - description: string - datePublished: string // in format like 'YYYY-mm-dd' - url: string - tags: string[] - liker: UserOAuthLikeCoin - // likerIp?: string - // userAgent?: string - }) => { - const endpoint = `${ENDPOINTS.iscnPublish}` - - if (!(cosmosWallet && liker)) { - throw new LikerISCNPublishWithoutWalletError('no liker or no wallet') - } - - const postData = { - recordNotes: 'Add IPFS fingerprint (by Matters.News)', - contentFingerprints: [ - // "hash://sha256/9564b85669d5e96ac969dd0161b8475bbced9e5999c6ec598da718a3045d6f2e", - mediaHash, - ipfsHash, // "ipfs://QmNrgEMcUygbKzZeZgYFosdd27VE9KnWbyUD73bKZJ3bGi111" - ], - stakeholders: [ - { - entity: { - '@id': `did:cosmos:${cosmosWallet}`, - name: userName, - }, - rewardProportion: 100, - contributionType: 'http://schema.org/author', - }, - { - rewardProportion: 0, - contributionType: 'http://schema.org/publisher', - entity: { - name: 'Matters.News', - }, - // "footprint": "https://en.wikipedia.org/wiki/Fibonacci_number", - // "description": "The blog post referred the matrix form of computing Fibonacci numbers." - }, - ], - type: 'Article', - name: title, - description, - datePublished, - url, - // "usageInfo": "https://creativecommons.org/licenses/by/4.0", - keywords: tags, - } - - const res = await this.request({ - endpoint, - // ip: likerIp, - // userAgent, - withClientCredential: true, - method: 'POST', - data: postData, - liker, - }) - - const data = _.get(res, 'data') - - const cache = new Cache(CACHE_PREFIX.LIKECOIN, this.redis) - await cache.storeObject({ - // keys: ['iscnPublish', userName, 'likerId', liker.likerId], - keys: { - type: 'iscnPublish', - id: userName, - field: 'likerId', - args: { likerId: liker.likerId, mediaHash }, - }, - data: { - postData, - resData: data, - }, - expire: CACHE_TTL.LONG, // save for 1 day - }) - - if (!data) { - logger.error('iscnPublish with no data: %j', res) - throw res - } - - if (!data.iscnId) { - logger.warn( - 'iscnPublish failed posted results: %j with: %j', - res, - postData - ) - } - - return data.iscnId - } - public getCosmosTxData = async ({ hash }: { hash: string }) => { const endpoint = `${ENDPOINTS.cosmosTx}/${hash}` const result = await this.request({ @@ -473,232 +274,4 @@ export class LikeCoin { const amount = _.get(msgSend, 'amount[0].amount') return { amount } } - - private updateCivicLikerCache = async (data: UpdateCivicLikerCacheData) => - this.aws.sqsSendMessage({ - messageBody: data, - queueUrl: QUEUE_URL.likecoinUpdateCivicLikerCache, - }) - - // Lambda handler implementations - public handleLike = async (data: LikeData) => { - const { likerId, url, authorLikerId } = data - const liker = await this.findLiker({ likerId }) - - if (likerId === authorLikerId) { - logger.info('cannot like self, skip.') - return - } - - if (!liker) { - throw new Error(`liker (${likerId}) not found.`) - } - - if (url.startsWith('https://matters.news')) { - await this.requestLike({ - liker, - ...data, - url: url.replace('https://matters.news', 'https://matters.town'), - }) - } else { - await this.requestLike({ - liker, - ...data, - }) - } - } - - public handleSendPV = async (data: SendPVData) => { - const { likerId } = data - const liker = - likerId === undefined - ? undefined - : (await this.findLiker({ likerId })) || undefined - - await this.requestCount({ - liker: liker, - ...data, - }) - } - - public handleUpdateCivicLikerCache = async ({ - likerId, - userId, - expire, - }: UpdateCivicLikerCacheData) => { - let isCivicLiker - const cache = new Cache(CACHE_PREFIX.CIVIC_LIKER, this.objectCacheRedis) - try { - isCivicLiker = await this.requestIsCivicLiker({ - likerId, - }) - } catch (e) { - // remove from cache so new request can trigger a retry - await cache.removeObject({ keys: { id: likerId } }) - throw e - } - - const hour = 60 * 60 - await this._handleUpdateCivicLikerCache({ - likerId, - userId, - isCivicLiker, - expire: expire + this.getRandomInt(1, hour), - }) - } - - public updateCivicLikerCaches = async ( - likerCacheData: BaseUpdateCivicLikerCacheData[] - ) => { - const likerIdToExpires = Object.fromEntries( - likerCacheData.map(({ likerId, expire }) => [likerId, expire]) - ) - const mattersLikerData = await this.knex('user') - .select('id', 'liker_id') - .whereIn( - 'liker_id', - likerCacheData.map(({ likerId }) => likerId) - ) - await Promise.all( - mattersLikerData.map(async ({ id, likerId }) => { - await this._handleUpdateCivicLikerCache({ - likerId, - userId: id, - isCivicLiker: true, - expire: likerIdToExpires[likerId], - }) - }) - ) - } - - private _handleUpdateCivicLikerCache = async ({ - likerId, - userId, - isCivicLiker, - expire, - }: { - likerId: string - userId: string - isCivicLiker: boolean - expire: number - }) => { - const cache = new Cache(CACHE_PREFIX.CIVIC_LIKER, this.objectCacheRedis) - // update cache - await cache.storeObject({ - keys: { id: likerId }, - data: isCivicLiker, - expire, - }) - - // invalidation should after data update - const { invalidateFQC } = await import('@matters/apollo-response-cache') - await invalidateFQC({ - node: { type: 'User', id: userId }, - redis: this.redis, - }) - } - - private requestLike = async ({ - authorLikerId, - liker, - url, - likerIp, - amount, - userAgent, - }: { - authorLikerId: string - liker: UserOAuthLikeCoin - url: string - likerIp?: string - amount: number - userAgent: string - }) => { - const endpoint = `${ENDPOINTS.like}/${authorLikerId}/${amount}` - const result = await this.request({ - ip: likerIp, - userAgent, - endpoint, - method: 'POST', - liker, - data: { - referrer: encodeURI(url), - }, - }) - const data = _.get(result, 'data') - if (data === 'OK') { - return data - } else { - throw result - } - } - - /** - * current user like count of a content - */ - private requestCount = async ({ - liker, - authorLikerId, - url, - likerIp, - userAgent, - }: { - liker?: UserOAuthLikeCoin - authorLikerId: string - url: string - likerIp?: string - userAgent: string - }) => { - const endpoint = `${ENDPOINTS.like}/${authorLikerId}/self` - const res = await this.request({ - endpoint, - method: 'GET', - liker, - ip: likerIp, - userAgent, - data: { - referrer: encodeURI(url), - }, - }) - const data = _.get(res, 'data') - logger.info('count response:', data) - - if (!data) { - throw res - } - - return data.count - } - - private requestIsCivicLiker = async ({ likerId }: { likerId: string }) => { - let res: any - try { - res = await this.request({ - endpoint: `/users/id/${likerId}/min`, - method: 'GET', - timeout: 2000, - }) - } catch (e: any) { - const code = e.response?.status as any - if (code === 404) { - logger.warn(`likerId ${likerId} not exist`) - return false - } - throw e - } - logger.info('civicLiker response:', res?.data) - return !!_.get(res, 'data.isSubscribedCivicLiker') - } - - private findLiker = async ({ - likerId, - }: { - likerId: string - }): Promise => - this.knex.select().from('user_oauth_likecoin').where({ likerId }).first() - - private getRandomInt = (min: number, max: number): number => { - min = Math.ceil(min) - max = Math.floor(max) - return Math.floor(Math.random() * (max - min)) + min - } } diff --git a/src/definitions/index.d.ts b/src/definitions/index.d.ts index 8d0202929..37efc5cef 100644 --- a/src/definitions/index.d.ts +++ b/src/definitions/index.d.ts @@ -7,7 +7,6 @@ import type { DraftService, ExchangeRate, MomentService, - LikeCoin, NotificationService, OAuthService, OpenSeaService, @@ -203,7 +202,6 @@ export interface DataSources { translationService: TranslationService channelService: ChannelService searchService: SearchService - likecoin: LikeCoin exchangeRate: ExchangeRate connections: Connections queues: { diff --git a/src/handlers/likecoinBatchUpdateCivicLikerCaches.ts b/src/handlers/likecoinBatchUpdateCivicLikerCaches.ts deleted file mode 100644 index 7c2ff6ca4..000000000 --- a/src/handlers/likecoinBatchUpdateCivicLikerCaches.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { LikeCoin } from '#connectors/likecoin/index.js' - -import { connections } from '../connections.js' - -type Event = { - body?: string - rawBody?: string - isBase64Encoded?: boolean -} - -const likecoin = new LikeCoin(connections) - -type CivicLikerUpdate = { - id: string - expires: number // unix timestamp -} - -// Usage: -// curl -X POST -H "Content-Type: application/json" -d '[{"id":"like_id1","expires":1718236800}]' https://some.lambda-url.ap-southeast-1.on.aws -export const handler = async (event: Event) => { - console.log('body:', event.body) - - let updates: CivicLikerUpdate[] = [] - - try { - // Parse the request body - if (event.body) { - const body = event.isBase64Encoded - ? Buffer.from(event.body, 'base64').toString() - : event.body - updates = JSON.parse(body) - } - - if (!validate(updates)) { - return { - statusCode: 400, - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - message: 'Unexpected input.', - }), - } - } - - const oneday = 86400 - - await likecoin.updateCivicLikerCaches( - updates.map(({ id, expires }) => { - const ttl = getTTL(expires) - - return { - likerId: id, - expire: ttl === 0 ? 1 : ttl + oneday, // zero expire is invalid for redis - } - }) - ) - return { - statusCode: 200, - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - message: 'succeeded.', - }), - } - } catch (e) { - console.error(e) - return { - statusCode: 500, - headers: { - 'content-type': 'application/json', - }, - body: JSON.stringify({ - message: 'failed.', - }), - } - } -} - -// return ttl in seconds -const getTTL = (expires: number): number => { - const ttl = +new Date(expires * 1000) - +Date.now() - return Math.ceil(Math.max(0, ttl) / 1000) -} - -const validate = (event: any): boolean => { - if (!Array.isArray(event)) { - return false - } - for (const i of event) { - if (typeof i.id !== 'string') { - return false - } - if (typeof i.expires !== 'number') { - return false - } - // check if unix time in seconds - if (i.expires.toString().length !== 10) { - return false - } - } - return true -} diff --git a/src/handlers/likecoinLike.ts b/src/handlers/likecoinLike.ts deleted file mode 100644 index 76570b0a7..000000000 --- a/src/handlers/likecoinLike.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { SQSEvent } from 'aws-lambda' - -import { LikeCoin } from '#connectors/likecoin/index.js' - -import { connections } from '../connections.js' - -const likecoin = new LikeCoin(connections) - -export const handler = async (event: SQSEvent) => { - const results = await Promise.allSettled( - event.Records.map(({ body }: { body: string }) => - likecoin.handleLike(JSON.parse(body)) - ) - ) - - // print failed reason - results.map((res: any) => { - if (res.status === 'rejected') { - console.error(res.reason) - } - }) - - // https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting - return { - batchItemFailures: results - .map((res: any, index: number) => { - if (res.status === 'rejected') { - return { itemIdentifier: event.Records[index].messageId } - } - }) - .filter(Boolean), - } -} diff --git a/src/handlers/likecoinUpdateCivicLikerCache.ts b/src/handlers/likecoinUpdateCivicLikerCache.ts deleted file mode 100644 index 13041c0a8..000000000 --- a/src/handlers/likecoinUpdateCivicLikerCache.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { SQSEvent } from 'aws-lambda' - -import { LikeCoin } from '#connectors/likecoin/index.js' - -import { connections } from '../connections.js' - -const likecoin = new LikeCoin(connections) - -export const handler = async (event: SQSEvent) => { - const results = await Promise.allSettled( - event.Records.map(({ body }: { body: string }) => - likecoin.handleUpdateCivicLikerCache(JSON.parse(body)) - ) - ) - - // print failed reason - results.map((res: any) => { - if (res.status === 'rejected') { - console.error(res.reason) - } - }) - - // https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting - return { - batchItemFailures: results - .map((res: any, index: number) => { - if (res.status === 'rejected') { - return { itemIdentifier: event.Records[index].messageId } - } - }) - .filter(Boolean), - } -} diff --git a/src/mutations/article/appreciateArticle.ts b/src/mutations/article/appreciateArticle.ts index 711f76a12..05849b42a 100644 --- a/src/mutations/article/appreciateArticle.ts +++ b/src/mutations/article/appreciateArticle.ts @@ -7,7 +7,6 @@ import { NOTICE_TYPE, NODE_TYPES, } from '#common/enums/index.js' -import { environment } from '#common/environment.js' import { ActionLimitExceededError, ArticleNotFoundError, @@ -17,7 +16,6 @@ import { UserInputError, } from '#common/errors.js' import { fromGlobalId } from '#common/utils/index.js' -import { LikeCoin } from '#connectors/index.js' import { invalidateFQC } from '@matters/apollo-response-cache' const resolver: GQLMutationResolvers['appreciateArticle'] = async ( @@ -102,19 +100,6 @@ const resolver: GQLMutationResolvers['appreciateArticle'] = async ( type: APPRECIATION_TYPES.like, }) - // insert record to LikeCoin - const likecoin = new LikeCoin(connections) - if (author.likerId && sender.likerId && author.likerId !== sender.likerId) { - likecoin.like({ - likerId: sender.likerId, - likerIp: viewer.ip, - userAgent: viewer.userAgent, - authorLikerId: author.likerId, - url: `https://${environment.siteDomain}/a/${article.shortHash}`, - amount: validAmount, - }) - } - // trigger notifications notificationService.trigger({ event: NOTICE_TYPE.article_new_appreciation, diff --git a/src/queries/user/liker/civicLiker.ts b/src/queries/user/liker/civicLiker.ts index 115a14637..9493ecaf4 100644 --- a/src/queries/user/liker/civicLiker.ts +++ b/src/queries/user/liker/civicLiker.ts @@ -1,20 +1,7 @@ import type { GQLLikerResolvers } from '#definitions/index.js' -const resolver: GQLLikerResolvers['civicLiker'] = async ( - { id }, - _, - { dataSources: { userService, likecoin } } -) => { - const liker = await userService.findLiker({ userId: id }) - - if (!liker) { - return false - } - - return likecoin.isCivicLiker({ - likerId: liker.likerId, - userId: id, - }) +const resolver: GQLLikerResolvers['civicLiker'] = async () => { + return false } export default resolver diff --git a/src/routes/graphql.ts b/src/routes/graphql.ts index ca71598c9..b26f1af8a 100644 --- a/src/routes/graphql.ts +++ b/src/routes/graphql.ts @@ -31,7 +31,6 @@ import { ChannelService, TranslationService, SearchService, - LikeCoin, ExchangeRate, } from '#connectors/index.js' import { @@ -158,7 +157,6 @@ export const graphql = async (app: Express) => { campaignService: new CampaignService(connections), channelService: new ChannelService(connections), openseaService: new OpenSeaService(), - likecoin: new LikeCoin(connections), exchangeRate: new ExchangeRate(connections.objectCacheRedis), translationService: new TranslationService(connections), notificationService: new NotificationService(connections),