|
@@ -4,7 +4,10 @@ import NotFoundException from '../../exceptions/NotFoundException'
|
|
|
import jsonResponseMiddleware, {
|
|
|
JsonResponse,
|
|
|
} from '../../middleware/jsonResponse.middleware'
|
|
|
-import twitterService, { GenerateResult } from '../../services/twitterService'
|
|
|
+import twitterService, {
|
|
|
+ GenerateResult,
|
|
|
+ ShotData,
|
|
|
+} from '../../services/twitterService'
|
|
|
import { PaginationConnection } from 'sequelize-cursor-pagination'
|
|
|
import { TweetData } from '../../db/models/Tweet'
|
|
|
import { MODIFY_TOKEN } from '../../constants'
|
|
@@ -15,6 +18,11 @@ interface ImportPayload {
|
|
|
urls: string[]
|
|
|
}
|
|
|
|
|
|
+interface ImportShotPayload {
|
|
|
+ token: string
|
|
|
+ shots: ShotData[]
|
|
|
+}
|
|
|
+
|
|
|
interface TopPayload {
|
|
|
token: string
|
|
|
statusId: string
|
|
@@ -47,6 +55,12 @@ export default class TweetController implements Controller {
|
|
|
jsonResponseMiddleware,
|
|
|
this.import as RequestHandler
|
|
|
)
|
|
|
+ this.router.post(
|
|
|
+ '/import_shot',
|
|
|
+ // apiKeyMiddleware(),
|
|
|
+ jsonResponseMiddleware,
|
|
|
+ this.importShot as RequestHandler
|
|
|
+ )
|
|
|
this.router.post(
|
|
|
'/top',
|
|
|
// apiKeyMiddleware(),
|
|
@@ -98,6 +112,27 @@ export default class TweetController implements Controller {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ private importShot(
|
|
|
+ request: Request<any, any, ImportShotPayload>,
|
|
|
+ response: JsonResponse<GenerateResult[]>,
|
|
|
+ next: NextFunction
|
|
|
+ ): void {
|
|
|
+ const { shots, token } = request.body
|
|
|
+ if (token !== MODIFY_TOKEN) {
|
|
|
+ response.status(401).jsonError('Unauthorized', 1012)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ twitterService
|
|
|
+ .bulkImportShot(shots)
|
|
|
+ .then((tweets) => {
|
|
|
+ response.jsonSuccess(tweets)
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ response.status(500).jsonError('Server Error', 1011)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
private top(
|
|
|
request: Request<any, any, TopPayload>,
|
|
|
response: JsonResponse<boolean>,
|