From 63c47fb09e747a04f28d042452a6d35940d6e9e1 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Thu, 13 Feb 2025 20:06:36 +0100 Subject: [PATCH] simple posting api --- .prettierrc | 5 + __pycache__/defines_py3.cpython-313.pyc | Bin 0 -> 1881 bytes next.config.ts | 6 +- package-lock.json | 120 +++++++++++++++++++++++- package.json | 14 ++- src/app/api/account/route.ts | 14 +++ src/app/api/posts/route.ts | 35 +++++++ src/app/api/route.ts | 11 +++ src/app/layout.tsx | 18 ++-- src/app/page.tsx | 115 ++++------------------- src/env.ts | 12 +++ src/platform.ts | 10 ++ 12 files changed, 243 insertions(+), 117 deletions(-) create mode 100644 .prettierrc create mode 100644 __pycache__/defines_py3.cpython-313.pyc create mode 100644 src/app/api/account/route.ts create mode 100644 src/app/api/posts/route.ts create mode 100644 src/app/api/route.ts create mode 100644 src/env.ts create mode 100644 src/platform.ts diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..97313f1 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 4, + "useTabs": false, + "singleQuote": true +} diff --git a/__pycache__/defines_py3.cpython-313.pyc b/__pycache__/defines_py3.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..555970afd2ba89a42f61da3f43488d20b0bba116 GIT binary patch literal 1881 zcma)6&rcgi6rQ!$U~l*pC6M4i*;0~tC6i`&j4VZ)q6TH|^h-9sI2Yc=H?sjGk z*oW3pFHv%6FOjNVn&gu9(&kdBe?rt#EG}rnAyRWmPpI?{=$kc5N!mk4+L=Amjg40ruATL;5_GX4 zu!I(N1dX1mYxCF^6@pbN68w2p154aAiCCpr)C|!sVo|m%T~lORGYu*TX>3=CL1zT< zsHvJ_n}$qkGcFG{Y)#gwXke@YS3x)PvaZ(z!TIIpd?InPNbGnzy|DAidSY(;>SBfN ztj_I7QZl(EX;CRVR~%o=E=Sd9a#D$}C*sOnYCW-(+1bwOshew2y_8=`E-ocgsWgzT z&gsQWY}!_%%M*BQE|!_qiK3@~l^Lf1-U%5I_Q|q7A zl~{UJ&RX+IHoYxJ7iwx|vA$edka0GfTsCwFzP&!XKI?SIih?Q4*=89V^$SJYw&+YG zQXsNb9NUx?oHxz#m||8UPKWEvsb)pij5@zHId;|QZ27h@p>Tl?7jZhVp<1S9*txt+ zvC};X2R;;D_BVPPUo^SCz5Yqh3X5QU+2qdcg@+z?HN%mo7k}+;#%?sjH=f0t z;gq-fZmiM!ynV3Az4J2I*%&wkcBHWM_8QAjH{GwnQ68X-PvU0Q5R%U!wBcb;+LP6> z2ccoK#!Vdg4gXT#2{b#%TkTEsM!UCsEGmADZ%JzHtmJ3X*a&)liH3S#6sB9Iy^%=0kvAOs1wjlS*1?9Vj4C?8x4>%4AbQWZC#AR+cgV=dRa7J zrWVvuOxaVq6_l{ta89v%PFUJ?D3;_RczWTZ_n~W`gD?t&?k2xV?T1c(J$P^MTmNq8 z%AJu{FdMix@D1G!U2crL>gc(jY@FXa(|7mcouR#SWS(g#mUk4sO-o<*CN zQjPP^h2bXm-hTh!_u=ot4_BVtesp`cKi)Wh_d`(mzBuwkcr5&IoCD<6;rM1_+!Eno8>uW$2stG9QOis Tzd)z{E literal 0 HcmV?d00001 diff --git a/next.config.ts b/next.config.ts index e9ffa30..b22af96 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,5 @@ -import type { NextConfig } from "next"; +import type { NextConfig } from 'next'; -const nextConfig: NextConfig = { - /* config options here */ -}; +const nextConfig: NextConfig = {}; export default nextConfig; diff --git a/package-lock.json b/package-lock.json index 4fc9bbd..40e4bbd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,19 @@ { "name": "klayrion", - "version": "0.1.0", + "version": "0.0.1-alpha.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "klayrion", - "version": "0.1.0", + "version": "0.0.1-alpha.0", "dependencies": { + "axios": "^1.7.9", + "instagram-graph-api": "^7.0.0", "next": "15.1.7", "react": "^19.0.0", - "react-dom": "^19.0.0" + "react-dom": "^19.0.0", + "twitter-api-v2": "^1.19.1" }, "devDependencies": { "@types/node": "^20", @@ -758,6 +761,23 @@ "dev": true, "license": "MIT" }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.7.9", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", + "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -931,6 +951,18 @@ "simple-swizzle": "^0.2.2" } }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -976,6 +1008,15 @@ "dev": true, "license": "MIT" }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/detect-libc": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz", @@ -1067,6 +1108,26 @@ "node": ">=8" } }, + "node_modules/follow-redirects": { + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/foreground-child": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", @@ -1084,6 +1145,20 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/form-data": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -1156,6 +1231,12 @@ "node": ">= 0.4" } }, + "node_modules/instagram-graph-api": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/instagram-graph-api/-/instagram-graph-api-7.0.0.tgz", + "integrity": "sha512-KZMdYOdPEiPCdB6NhfsAPmeqy9wvs4L+Vog9o0uA/3i8nHF8vURCVpHaerJ99Sd9AOpMRdy9HV9g0cL1QSUEZg==", + "license": "MIT" + }, "node_modules/is-arrayish": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", @@ -1319,6 +1400,27 @@ "node": ">=8.6" } }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, "node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -1717,6 +1819,12 @@ "dev": true, "license": "MIT" }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", @@ -2210,6 +2318,12 @@ "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, + "node_modules/twitter-api-v2": { + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/twitter-api-v2/-/twitter-api-v2-1.19.1.tgz", + "integrity": "sha512-X7+j1/VBiynw443ugDtEbFspYrWN26WH117uFc89K1+FkAgcSvj2GGMF8mIWPag2K4eS1Vd5HW35zorNdTveOg==", + "license": "Apache-2.0" + }, "node_modules/typescript": { "version": "5.7.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", diff --git a/package.json b/package.json index 499b5ba..da90f45 100644 --- a/package.json +++ b/package.json @@ -1,24 +1,28 @@ { "name": "klayrion", - "version": "0.1.0", + "version": "0.0.1-alpha.0", "private": true, "scripts": { "dev": "next dev", "build": "next build", "start": "next start", - "lint": "next lint" + "lint": "next lint", + "test": "node test.mjs" }, "dependencies": { + "axios": "^1.7.9", + "instagram-graph-api": "^7.0.0", + "next": "15.1.7", "react": "^19.0.0", "react-dom": "^19.0.0", - "next": "15.1.7" + "twitter-api-v2": "^1.19.1" }, "devDependencies": { - "typescript": "^5", "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", "postcss": "^8", - "tailwindcss": "^3.4.1" + "tailwindcss": "^3.4.1", + "typescript": "^5" } } diff --git a/src/app/api/account/route.ts b/src/app/api/account/route.ts new file mode 100644 index 0000000..3eba8a4 --- /dev/null +++ b/src/app/api/account/route.ts @@ -0,0 +1,14 @@ +import { NextResponse, NextRequest } from 'next/server'; +import { TwitterApi } from 'twitter-api-v2'; +import config from '@/env'; +import { PostRequest } from '@/platform'; +import { inspect } from 'util'; + +export async function POST(req: NextRequest) { + return NextResponse.json( + { + message: 'ok, feature not available yet', + }, + { status: 200 } + ); +} diff --git a/src/app/api/posts/route.ts b/src/app/api/posts/route.ts new file mode 100644 index 0000000..6dac292 --- /dev/null +++ b/src/app/api/posts/route.ts @@ -0,0 +1,35 @@ +import { NextResponse, NextRequest } from 'next/server'; +import { TwitterApi } from 'twitter-api-v2'; +import config from '@/env'; +import { PostRequest } from '@/platform'; +import { inspect } from 'util'; + +export async function POST(req: NextRequest) { + const { content, platforms }: PostRequest = await req.json(); + + try { + for (const platform of platforms) { + switch (platform.platform) { + // X / Twitter + case 'x': + const twitterClient = new TwitterApi({ + appKey: config.twitter.key, + appSecret: config.twitter.secret, + accessToken: platform.token, + accessSecret: platform.secret, + }); + + await twitterClient.v2.tweet(content); + } + } + } catch (err) { + console.log(inspect(err, true, null, true)); + } + + return NextResponse.json( + { + message: 'ok', + }, + { status: 200 } + ); +} diff --git a/src/app/api/route.ts b/src/app/api/route.ts new file mode 100644 index 0000000..29cac98 --- /dev/null +++ b/src/app/api/route.ts @@ -0,0 +1,11 @@ +import { NextResponse, NextRequest } from 'next/server'; + +export async function GET(request: NextRequest) { + return NextResponse.json( + { + message: 'ok', + version: '0.0.1-alpha.0', + }, + { status: 200 } + ); +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index f7fa87e..f7aed59 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,19 +1,21 @@ import type { Metadata } from "next"; -import { Geist, Geist_Mono } from "next/font/google"; +import { Roboto, Roboto_Mono } from "next/font/google"; import "./globals.css"; -const geistSans = Geist({ - variable: "--font-geist-sans", +const roboto = Roboto({ + weight: "500", subsets: ["latin"], + variable: "--font-roboto", }); -const geistMono = Geist_Mono({ - variable: "--font-geist-mono", +const robotoMono = Roboto_Mono({ + weight: "500", subsets: ["latin"], + variable: "--font-roboto-mono", }); export const metadata: Metadata = { - title: "Create Next App", + title: "Klayrion: The best AI social media scheduling tool", description: "Generated by create next app", }; @@ -24,9 +26,7 @@ export default function RootLayout({ }>) { return ( - + {children} diff --git a/src/app/page.tsx b/src/app/page.tsx index 3eee014..50a426d 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,101 +1,24 @@ -import Image from "next/image"; +'use client'; + +import { PostRequest } from '@/platform'; export default function Home() { - return ( -
-
- Next.js logo -
    -
  1. - Get started by editing{" "} - - src/app/page.tsx - - . -
  2. -
  3. Save and see your changes instantly.
  4. -
+ const test: PostRequest = { + content: 'Hello, World - Idk, Made this post for testing my API lol', + platforms: [], + }; - -
- -
- ); + Post now + + ); } diff --git a/src/env.ts b/src/env.ts new file mode 100644 index 0000000..b7fd63b --- /dev/null +++ b/src/env.ts @@ -0,0 +1,12 @@ +function error(name: string): string { + throw `'${name}' not found in '.env'`; +} + +const config = { + twitter: { + key: process.env.TWITTER_KEY || error('TWITTER_KEY'), + secret: process.env.TWITTER_SECRET || error('TWITTER_SECRET'), + }, +}; + +export default config; diff --git a/src/platform.ts b/src/platform.ts new file mode 100644 index 0000000..a2b706b --- /dev/null +++ b/src/platform.ts @@ -0,0 +1,10 @@ +export interface Platform { + platform: 'x'; + token: string; + secret: string; +} + +export interface PostRequest { + content: string; + platforms: Platform[]; +}