diff --git a/.eslintignore b/.eslintignore index 40bfc89..2709d9e 100644 --- a/.eslintignore +++ b/.eslintignore @@ -121,4 +121,6 @@ jwtRS256.key jwtRS256.key.pub #markdown files -**/*.md \ No newline at end of file +**/*.md + +*/**/.json \ No newline at end of file diff --git a/.gitignore b/.gitignore index 23a5824..2caeae7 100644 --- a/.gitignore +++ b/.gitignore @@ -131,9 +131,10 @@ dist .husky -yarn.lock -package-lock.json -build +*/**/yarn.lock +*/**/package-lock.json +*/**/build +*/**/dist !uploads/.gitkeep uploads/*.png @@ -146,4 +147,12 @@ uploads/*.mp4 uploads/*.mp3 uploads/*.zip uploads/*.rar -uploads/*.pdf \ No newline at end of file +uploads/*.pdf + +*/**/node_modules +*/**/.env + +yarn.lock +package-lock.json +build +dist \ No newline at end of file diff --git a/.graphqlrc.yaml b/.graphqlrc.yaml index 3151b3f..494194e 100644 --- a/.graphqlrc.yaml +++ b/.graphqlrc.yaml @@ -1,5 +1,5 @@ -schema: 'graphql/schema.graphql' -documents: 'services/*.ts' +schema: 'packages/api/graphql/schema.graphql' +documents: 'packages/api/services/*.ts' extensions: languageService: cacheSchemaFileForLookup: true diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..b1215e8 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +v18.16.0 \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..203e167 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,119 @@ +## Contributing Guidelines + +Thank you for considering contributing to our custom ShareX server! We appreciate your interest in making our project better. To ensure a smooth collaboration, please take a moment to review and follow these guidelines. + +## Table of Contents + +- [Contributing Guidelines](#contributing-guidelines) +- [Table of Contents](#table-of-contents) +- [Getting Started](#getting-started) + - [Prerequisites](#prerequisites) + - [Installation](#installation) +- [Project Structure](#project-structure) + - [API](#api) + - [CLI](#cli) + - [Dashboard](#dashboard) +- [Contribution Process](#contribution-process) + - [Reporting Issues](#reporting-issues) + - [Submitting Pull Requests](#submitting-pull-requests) + +## Getting Started + +To contribute to our custom ShareX server, follow these steps to set up the development environment. + +### Prerequisites + +- Node.js (version 18.X.X) +- WSL (Windows Subsystem for Linux) (for Windows users) +- Yarn (version 2.X.X) + +### Installation + +1. Fork the repository on GitHub. +2. Clone the forked repository to your local machine. +3. Install the required dependencies by running the following command in the project root directory: + + ``` + npm install + ``` + +4. Edit `.env` inside `packages/api`. Start the API server by running the following command: + + ``` + cd packages/api + yarn dev + ``` + +5. Start the CLI by running the following command: + + ``` + cd packages/cli + yarn r + ``` + +6. Edit `.env` inside `packages/frontend`. Start the Dashboard by running the following command: + + ``` + cd packages/frontend + yarn dev + ``` + +## Project Structure + +Our custom ShareX server is organized as a monorepo with the following packages: + +### API + +The API package contains the server-side code responsible for handling file, image, and text uploads, as well as URL shortening. It provides the core functionality of the ShareX server. + +### CLI + +The CLI package includes the command-line interface (CLI) for interacting with the ShareX server from the terminal. It allows users to perform various actions, such as uploading files, images, or text, and generating short URLs. + +### Dashboard + +The Dashboard package consists of the web-based admin dashboard for managing files, images, or text, and generated short URLs. It provides an intuitive interface for administrators to manage the ShareX server. + +## Contribution Process + +We welcome contributions from the community. If you encounter issues, have ideas for improvements, or want to contribute code, please follow the guidelines below. + +### Reporting Issues + +If you encounter any problems while using the ShareX server, please open an issue on the GitHub repository. Make sure to include detailed information about the issue, including steps to reproduce, expected behavior, and any relevant error messages. + +### Submitting Pull Requests + +If you want to contribute code to the project, follow these steps: + +1. Create a fork of the repository on GitHub. + +2. Clone the forked repository to your local machine: + ```bash + git clone https://github.com//shx.git + cd shx + ``` + +3. Create a new branch for your changes: + ```bash + git checkout -b feat/new-feature + ``` +4. Make your changes to the codebase. + +5. Test your changes to ensure they work as intended. + +6. Commit your changes with a clear and descriptive commit message: + ```bash + git commit -m "Add new feature" + ``` + +7. Push to your branch: + ```bash + git push origin feat/new-feature + ``` + +8. Open a pull request on the GitHub repository. Make sure to include a detailed description of your changes. + +9. Wait for a maintainer to review your pull request. If there are any issues, you may be asked to make changes to your code. Otherwise, your pull request will be merged into the main branch. + +10. Celebrate! 🎉 \ No newline at end of file diff --git a/README.md b/README.md index dc4d903..a813532 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# 🚀 **SHX SERVER** +# 🚀 **Project SHX** ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bravo68web/shx/build.yaml?style=for-the-badge) ![GitHub last commit](https://img.shields.io/github/last-commit/bravo68web/shx?style=for-the-badge) @@ -11,7 +11,9 @@ ## 📝 Description -Shx is a custom ShareX server that allows you to upload and share files, images, text and URLs with ease. This server is built using Node.js and Express.js and stores the uploaded content on AWS S3 and Redis. +Shx is a custom ShareX server that allows you to upload and share files, images, +text and URLs with ease. This server is built using Node.js and Express.js and +stores the uploaded content on AWS S3 and Redis. ## 🛠️ Technologies Used @@ -21,6 +23,8 @@ Shx is a custom ShareX server that allows you to upload and share files, images, - Redis - Cloudflare R2 - Hasura Graphql (with PostgreSQL) +- Next.JS +- Commander.js ## 🚀 Features @@ -28,22 +32,8 @@ Shx is a custom ShareX server that allows you to upload and share files, images, - Image upload - Text upload - URL shortener - -## 🚀 Getting Started - -To get started with the project, follow these steps: - -1. Clone the repo. -2. Run `npm install` to install dependencies. -3. Copy the `.env.example` file and create a `.env` file with your environment variables. -4. Run `npm run dev` to start the development server. - -## 📜 Scripts - -- `npm run dev`: Starts the development server. -- `npm run build`: Builds the project. -- `npm start`: Starts the project. -- `npm run prettier`: Runs Prettier to format code. +- CLI Support +- Admin Dashboard ## 📝 License @@ -53,4 +43,5 @@ For more information, please see the `LICENSE` file. ## 📧 Contact -If you have any questions or would like to contribute to the project, please contact `hi@b68.dev`. \ No newline at end of file +If you have any questions or would like to contribute to the project, please +contact `hi@b68.dev`. \ No newline at end of file diff --git a/package.json b/package.json index fd6246c..27c8967 100644 --- a/package.json +++ b/package.json @@ -1,73 +1,21 @@ { - "name": "shx-daddy", + "name": "shx", "version": "1.0.0", - "description": "My ShareX Server acting as Daddy", - "main": "index.ts", - "repository": "https://github.com/bravo68web/shx.git", - "author": { - "email": "hi@b68.dev", - "name": "Jyotirmoy Bandyopadhayaya", - "url": "https://b68.dev" - }, - "license": "ISC", - "type": "module", + "description": "Private Data Hosting Service", + "repository": "git@github.com:BRAVO68WEB/shx.git", + "author": "Jyotirmoy Bandyopadhyaya [Bravo68] ", + "license": "MIT", "private": true, - "dependencies": { - "@aws-sdk/client-s3": "^3.226.0", - "axios": "^1.2.1", - "cors": "^2.8.5", - "dotenv": "^16.0.3", - "envfile": "^6.18.0", - "express": "^4.18.2", - "form-data": "^4.0.0", - "graphql": "^16.6.0", - "graphql-request": "^5.0.0", - "helmet": "^6.0.1", - "joi": "^17.7.0", - "morgan": "^1.10.0", - "multer": "^1.4.5-lts.1", - "multer-s3": "^3.0.1", - "napi-nanoid": "^0.0.4", - "node-cache": "^5.1.2", - "nodemailer": "^6.8.0", - "redis": "^4.5.1", - "sharp": "^0.32.1" - }, + "workspaces": [ + "packages/*" + ], "scripts": { - "dev": "concurrently \"npm run dev:express\" \"npm run dev:hasura\"", - "dev:hasura": "cd hasura && hasura --skip-update-check --envfile ../.env console", - "dev:express": "cross-env NODE_ENV=development nodemon -x node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm index.ts --signal SIGKILL --ignore node_modules", - "build": "tsc -p tsconfig.json", - "start": "node --es-module-specifier-resolution=node --loader ts-node/esm ./build/index.js", "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,css,scss,md}\"", "prepare": "husky install", - "fetch:schemas": "bash bin/fetch-gql-schema.sh", "configure-husky": "npx husky install && npx husky add .husky/pre-commit \"npx --no-install lint-staged\"" }, - "devDependencies": { - "@swc/core": "^1.3.23", - "@swc/wasm": "^1.3.23", - "@types/cors": "^2.8.13", - "@types/express": "^4.17.14", - "@types/morgan": "^1.9.3", - "@types/multer": "^1.4.7", - "@typescript-eslint/eslint-plugin": "^5.54.1", - "@typescript-eslint/parser": "^5.54.1", - "concurrently": "^7.6.0", - "cross-env": "^7.0.3", - "eslint": "^8.35.0", - "eslint-config-prettier": "^8.7.0", - "graphqurl": "^1.0.1", - "hasura-cli": "^2.15.1", - "husky": "^8.0.3", - "lint-staged": "^13.1.2", - "nodemon": "^2.0.22", - "prettier": "^2.8.2", - "ts-node": "^10.9.1", - "typescript": "^4.9.3" - }, "lint-staged": { - "**/*.{js,json,ts,css}": [ + "**/*.{js,ts}": [ "eslint --fix", "prettier --write" ] @@ -76,5 +24,9 @@ "hooks": { "pre-commit": "lint-staged" } + }, + "devDependencies": { + "husky": "^8.0.3", + "prettier": "^2.8.8" } } diff --git a/.env.example b/packages/api/.env.example similarity index 100% rename from .env.example rename to packages/api/.env.example diff --git a/packages/api/.gitignore b/packages/api/.gitignore new file mode 100644 index 0000000..2319e55 --- /dev/null +++ b/packages/api/.gitignore @@ -0,0 +1,2 @@ +.env.prod +.env.dev \ No newline at end of file diff --git a/Dockerfile b/packages/api/Dockerfile similarity index 100% rename from Dockerfile rename to packages/api/Dockerfile diff --git a/packages/api/README.md b/packages/api/README.md new file mode 100644 index 0000000..31763cb --- /dev/null +++ b/packages/api/README.md @@ -0,0 +1,60 @@ +# 🚀 **SHX API** + +![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bravo68web/shx/build.yaml?style=for-the-badge) +![GitHub last commit](https://img.shields.io/github/last-commit/bravo68web/shx?style=for-the-badge) +![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/bravo68web/shx?style=for-the-badge) +![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/bravo68web/shx?style=for-the-badge) + +[![forthebadge](https://forthebadge.com/images/badges/made-with-typescript.svg)](https://forthebadge.com) +[![forthebadge](https://forthebadge.com/images/badges/powered-by-black-magic.svg)](https://forthebadge.com) +[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com) + +## 📝 Description + +Shx is a custom ShareX server that allows you to upload and share files, images, +text and URLs with ease. This server is built using Node.js and Express.js and +stores the uploaded content on AWS S3 and Redis. + +## 🛠️ Technologies Used + +- Node.js +- Express.js +- TypeScript +- Redis +- Cloudflare R2 +- Hasura Graphql (with PostgreSQL) + +## 🚀 Features + +- File upload +- Image upload +- Text upload +- URL shortener + +## 🚀 Getting Started + +To get started with the project, follow these steps: + +1. Clone the repo. +2. Run `npm install` to install dependencies. +3. Copy the `.env.example` file and create a `.env` file with your environment + variables. +4. Run `npm run dev` to start the development server. + +## 📜 Scripts + +- `npm run dev`: Starts the development server. +- `npm run build`: Builds the project. +- `npm start`: Starts the project. +- `npm run prettier`: Runs Prettier to format code. + +## 📝 License + +This project is licensed under the ISC License. + +For more information, please see the `LICENSE` file. + +## 📧 Contact + +If you have any questions or would like to contribute to the project, please +contact `hi@b68.dev`. diff --git a/bin/fetch-gql-schema.sh b/packages/api/bin/fetch-gql-schema.sh similarity index 100% rename from bin/fetch-gql-schema.sh rename to packages/api/bin/fetch-gql-schema.sh diff --git a/configs/index.ts b/packages/api/configs/index.ts similarity index 100% rename from configs/index.ts rename to packages/api/configs/index.ts diff --git a/controllers/apikey.controller.ts b/packages/api/controllers/apikey.controller.ts similarity index 100% rename from controllers/apikey.controller.ts rename to packages/api/controllers/apikey.controller.ts diff --git a/controllers/gists.controller.ts b/packages/api/controllers/gists.controller.ts similarity index 100% rename from controllers/gists.controller.ts rename to packages/api/controllers/gists.controller.ts diff --git a/controllers/sxcu.controller.ts b/packages/api/controllers/sxcu.controller.ts similarity index 100% rename from controllers/sxcu.controller.ts rename to packages/api/controllers/sxcu.controller.ts diff --git a/controllers/upload.controller.ts b/packages/api/controllers/upload.controller.ts similarity index 100% rename from controllers/upload.controller.ts rename to packages/api/controllers/upload.controller.ts diff --git a/controllers/urlstore.controller.ts b/packages/api/controllers/urlstore.controller.ts similarity index 100% rename from controllers/urlstore.controller.ts rename to packages/api/controllers/urlstore.controller.ts diff --git a/data/uploader.service.ts b/packages/api/data/uploader.service.ts similarity index 100% rename from data/uploader.service.ts rename to packages/api/data/uploader.service.ts diff --git a/graphql/schema.graphql b/packages/api/graphql/schema.graphql similarity index 83% rename from graphql/schema.graphql rename to packages/api/graphql/schema.graphql index 0beec49..cfa91ef 100644 --- a/graphql/schema.graphql +++ b/packages/api/graphql/schema.graphql @@ -99,8 +99,80 @@ input String_comparison_exp { """API Keys Allowed""" type apikeys { created_at: timestamptz! + + """An array relationship""" + gists( + """distinct select on columns""" + distinct_on: [gists_select_column!] + + """limit the number of rows returned""" + limit: Int + + """skip the first n rows. Use only with order_by""" + offset: Int + + """sort the rows by one or more columns""" + order_by: [gists_order_by!] + + """filter the rows returned""" + where: gists_bool_exp + ): [gists!]! + + """An aggregate relationship""" + gists_aggregate( + """distinct select on columns""" + distinct_on: [gists_select_column!] + + """limit the number of rows returned""" + limit: Int + + """skip the first n rows. Use only with order_by""" + offset: Int + + """sort the rows by one or more columns""" + order_by: [gists_order_by!] + + """filter the rows returned""" + where: gists_bool_exp + ): gists_aggregate! key: String! keyID: uuid! + + """An array relationship""" + shorturls( + """distinct select on columns""" + distinct_on: [shorturls_select_column!] + + """limit the number of rows returned""" + limit: Int + + """skip the first n rows. Use only with order_by""" + offset: Int + + """sort the rows by one or more columns""" + order_by: [shorturls_order_by!] + + """filter the rows returned""" + where: shorturls_bool_exp + ): [shorturls!]! + + """An aggregate relationship""" + shorturls_aggregate( + """distinct select on columns""" + distinct_on: [shorturls_select_column!] + + """limit the number of rows returned""" + limit: Int + + """skip the first n rows. Use only with order_by""" + offset: Int + + """sort the rows by one or more columns""" + order_by: [shorturls_order_by!] + + """filter the rows returned""" + where: shorturls_bool_exp + ): shorturls_aggregate! updated_at: timestamptz! """An array relationship""" @@ -165,8 +237,12 @@ input apikeys_bool_exp { _not: apikeys_bool_exp _or: [apikeys_bool_exp!] created_at: timestamptz_comparison_exp + gists: gists_bool_exp + gists_aggregate: gists_aggregate_bool_exp key: String_comparison_exp keyID: uuid_comparison_exp + shorturls: shorturls_bool_exp + shorturls_aggregate: shorturls_aggregate_bool_exp updated_at: timestamptz_comparison_exp uploads: uploads_bool_exp uploads_aggregate: uploads_aggregate_bool_exp @@ -192,8 +268,10 @@ input type for inserting data into table "apikeys" """ input apikeys_insert_input { created_at: timestamptz + gists: gists_arr_rel_insert_input key: String keyID: uuid + shorturls: shorturls_arr_rel_insert_input updated_at: timestamptz uploads: uploads_arr_rel_insert_input } @@ -247,8 +325,10 @@ input apikeys_on_conflict { """Ordering options when selecting data from "apikeys".""" input apikeys_order_by { created_at: order_by + gists_aggregate: gists_aggregate_order_by key: order_by keyID: order_by + shorturls_aggregate: shorturls_aggregate_order_by updated_at: order_by uploads_aggregate: uploads_aggregate_order_by } @@ -342,6 +422,8 @@ enum cursor_ordering { columns and relationships of "gists" """ type gists { + """An object relationship""" + apikey: apikeys! apikeyUsed: uuid! content: String! created_on: timestamptz! @@ -362,6 +444,33 @@ type gists_aggregate { nodes: [gists!]! } +input gists_aggregate_bool_exp { + bool_and: gists_aggregate_bool_exp_bool_and + bool_or: gists_aggregate_bool_exp_bool_or + count: gists_aggregate_bool_exp_count +} + +input gists_aggregate_bool_exp_bool_and { + arguments: gists_select_column_gists_aggregate_bool_exp_bool_and_arguments_columns! + distinct: Boolean + filter: gists_bool_exp + predicate: Boolean_comparison_exp! +} + +input gists_aggregate_bool_exp_bool_or { + arguments: gists_select_column_gists_aggregate_bool_exp_bool_or_arguments_columns! + distinct: Boolean + filter: gists_bool_exp + predicate: Boolean_comparison_exp! +} + +input gists_aggregate_bool_exp_count { + arguments: [gists_select_column!] + distinct: Boolean + filter: gists_bool_exp + predicate: Int_comparison_exp! +} + """ aggregate fields of "gists" """ @@ -379,11 +488,45 @@ type gists_aggregate_fields { variance: gists_variance_fields } +""" +order by aggregate values of table "gists" +""" +input gists_aggregate_order_by { + avg: gists_avg_order_by + count: order_by + max: gists_max_order_by + min: gists_min_order_by + stddev: gists_stddev_order_by + stddev_pop: gists_stddev_pop_order_by + stddev_samp: gists_stddev_samp_order_by + sum: gists_sum_order_by + var_pop: gists_var_pop_order_by + var_samp: gists_var_samp_order_by + variance: gists_variance_order_by +} + +""" +input type for inserting array relation for remote table "gists" +""" +input gists_arr_rel_insert_input { + data: [gists_insert_input!]! + + """upsert condition""" + on_conflict: gists_on_conflict +} + """aggregate avg on columns""" type gists_avg_fields { views: Float } +""" +order by avg() on columns of table "gists" +""" +input gists_avg_order_by { + views: order_by +} + """ Boolean expression to filter rows from the table "gists". All fields are combined with a logical 'AND'. """ @@ -391,6 +534,7 @@ input gists_bool_exp { _and: [gists_bool_exp!] _not: gists_bool_exp _or: [gists_bool_exp!] + apikey: apikeys_bool_exp apikeyUsed: uuid_comparison_exp content: String_comparison_exp created_on: timestamptz_comparison_exp @@ -434,6 +578,7 @@ input gists_inc_input { input type for inserting data into table "gists" """ input gists_insert_input { + apikey: apikeys_obj_rel_insert_input apikeyUsed: uuid content: String created_on: timestamptz @@ -458,6 +603,20 @@ type gists_max_fields { views: numeric } +""" +order by max() on columns of table "gists" +""" +input gists_max_order_by { + apikeyUsed: order_by + content: order_by + created_on: order_by + creator_ip: order_by + gistID: order_by + gist_url_key: order_by + passkey: order_by + views: order_by +} + """aggregate min on columns""" type gists_min_fields { apikeyUsed: uuid @@ -470,6 +629,20 @@ type gists_min_fields { views: numeric } +""" +order by min() on columns of table "gists" +""" +input gists_min_order_by { + apikeyUsed: order_by + content: order_by + created_on: order_by + creator_ip: order_by + gistID: order_by + gist_url_key: order_by + passkey: order_by + views: order_by +} + """ response of any mutation on the table "gists" """ @@ -492,6 +665,7 @@ input gists_on_conflict { """Ordering options when selecting data from "gists".""" input gists_order_by { + apikey: apikeys_order_by apikeyUsed: order_by content: order_by created_on: order_by @@ -544,6 +718,28 @@ enum gists_select_column { views } +""" +select "gists_aggregate_bool_exp_bool_and_arguments_columns" columns of table "gists" +""" +enum gists_select_column_gists_aggregate_bool_exp_bool_and_arguments_columns { + """column name""" + isOneTimeOnly + + """column name""" + isPrivate +} + +""" +select "gists_aggregate_bool_exp_bool_or_arguments_columns" columns of table "gists" +""" +enum gists_select_column_gists_aggregate_bool_exp_bool_or_arguments_columns { + """column name""" + isOneTimeOnly + + """column name""" + isPrivate +} + """ input type for updating data in table "gists" """ @@ -565,16 +761,37 @@ type gists_stddev_fields { views: Float } +""" +order by stddev() on columns of table "gists" +""" +input gists_stddev_order_by { + views: order_by +} + """aggregate stddev_pop on columns""" type gists_stddev_pop_fields { views: Float } +""" +order by stddev_pop() on columns of table "gists" +""" +input gists_stddev_pop_order_by { + views: order_by +} + """aggregate stddev_samp on columns""" type gists_stddev_samp_fields { views: Float } +""" +order by stddev_samp() on columns of table "gists" +""" +input gists_stddev_samp_order_by { + views: order_by +} + """ Streaming cursor of the table "gists" """ @@ -605,6 +822,13 @@ type gists_sum_fields { views: numeric } +""" +order by sum() on columns of table "gists" +""" +input gists_sum_order_by { + views: order_by +} + """ update columns of table "gists" """ @@ -656,16 +880,37 @@ type gists_var_pop_fields { views: Float } +""" +order by var_pop() on columns of table "gists" +""" +input gists_var_pop_order_by { + views: order_by +} + """aggregate var_samp on columns""" type gists_var_samp_fields { views: Float } +""" +order by var_samp() on columns of table "gists" +""" +input gists_var_samp_order_by { + views: order_by +} + """aggregate variance on columns""" type gists_variance_fields { views: Float } +""" +order by variance() on columns of table "gists" +""" +input gists_variance_order_by { + views: order_by +} + """mutation root""" type mutation_root { """ @@ -1015,9 +1260,7 @@ type query_root { """fetch data from the table: "apikeys" using primary key columns""" apikeys_by_pk(keyID: uuid!): apikeys - """ - fetch data from the table: "gists" - """ + """An array relationship""" gists( """distinct select on columns""" distinct_on: [gists_select_column!] @@ -1035,9 +1278,7 @@ type query_root { where: gists_bool_exp ): [gists!]! - """ - fetch aggregated fields from the table: "gists" - """ + """An aggregate relationship""" gists_aggregate( """distinct select on columns""" distinct_on: [gists_select_column!] @@ -1058,9 +1299,7 @@ type query_root { """fetch data from the table: "gists" using primary key columns""" gists_by_pk(gistID: uuid!): gists - """ - fetch data from the table: "shorturls" - """ + """An array relationship""" shorturls( """distinct select on columns""" distinct_on: [shorturls_select_column!] @@ -1078,9 +1317,7 @@ type query_root { where: shorturls_bool_exp ): [shorturls!]! - """ - fetch aggregated fields from the table: "shorturls" - """ + """An aggregate relationship""" shorturls_aggregate( """distinct select on columns""" distinct_on: [shorturls_select_column!] @@ -1143,6 +1380,8 @@ type query_root { """All Short URLs""" type shorturls { + """An object relationship""" + apikey: apikeys! apikeyUsed: uuid! clicks: Int! created_on: timestamptz! @@ -1160,6 +1399,17 @@ type shorturls_aggregate { nodes: [shorturls!]! } +input shorturls_aggregate_bool_exp { + count: shorturls_aggregate_bool_exp_count +} + +input shorturls_aggregate_bool_exp_count { + arguments: [shorturls_select_column!] + distinct: Boolean + filter: shorturls_bool_exp + predicate: Int_comparison_exp! +} + """ aggregate fields of "shorturls" """ @@ -1177,11 +1427,45 @@ type shorturls_aggregate_fields { variance: shorturls_variance_fields } +""" +order by aggregate values of table "shorturls" +""" +input shorturls_aggregate_order_by { + avg: shorturls_avg_order_by + count: order_by + max: shorturls_max_order_by + min: shorturls_min_order_by + stddev: shorturls_stddev_order_by + stddev_pop: shorturls_stddev_pop_order_by + stddev_samp: shorturls_stddev_samp_order_by + sum: shorturls_sum_order_by + var_pop: shorturls_var_pop_order_by + var_samp: shorturls_var_samp_order_by + variance: shorturls_variance_order_by +} + +""" +input type for inserting array relation for remote table "shorturls" +""" +input shorturls_arr_rel_insert_input { + data: [shorturls_insert_input!]! + + """upsert condition""" + on_conflict: shorturls_on_conflict +} + """aggregate avg on columns""" type shorturls_avg_fields { clicks: Float } +""" +order by avg() on columns of table "shorturls" +""" +input shorturls_avg_order_by { + clicks: order_by +} + """ Boolean expression to filter rows from the table "shorturls". All fields are combined with a logical 'AND'. """ @@ -1189,6 +1473,7 @@ input shorturls_bool_exp { _and: [shorturls_bool_exp!] _not: shorturls_bool_exp _or: [shorturls_bool_exp!] + apikey: apikeys_bool_exp apikeyUsed: uuid_comparison_exp clicks: Int_comparison_exp created_on: timestamptz_comparison_exp @@ -1224,6 +1509,7 @@ input shorturls_inc_input { input type for inserting data into table "shorturls" """ input shorturls_insert_input { + apikey: apikeys_obj_rel_insert_input apikeyUsed: uuid clicks: Int created_on: timestamptz @@ -1244,6 +1530,19 @@ type shorturls_max_fields { urlID: uuid } +""" +order by max() on columns of table "shorturls" +""" +input shorturls_max_order_by { + apikeyUsed: order_by + clicks: order_by + created_on: order_by + creator_ip: order_by + original_url: order_by + short_key: order_by + urlID: order_by +} + """aggregate min on columns""" type shorturls_min_fields { apikeyUsed: uuid @@ -1255,6 +1554,19 @@ type shorturls_min_fields { urlID: uuid } +""" +order by min() on columns of table "shorturls" +""" +input shorturls_min_order_by { + apikeyUsed: order_by + clicks: order_by + created_on: order_by + creator_ip: order_by + original_url: order_by + short_key: order_by + urlID: order_by +} + """ response of any mutation on the table "shorturls" """ @@ -1277,6 +1589,7 @@ input shorturls_on_conflict { """Ordering options when selecting data from "shorturls".""" input shorturls_order_by { + apikey: apikeys_order_by apikeyUsed: order_by clicks: order_by created_on: order_by @@ -1335,16 +1648,37 @@ type shorturls_stddev_fields { clicks: Float } +""" +order by stddev() on columns of table "shorturls" +""" +input shorturls_stddev_order_by { + clicks: order_by +} + """aggregate stddev_pop on columns""" type shorturls_stddev_pop_fields { clicks: Float } +""" +order by stddev_pop() on columns of table "shorturls" +""" +input shorturls_stddev_pop_order_by { + clicks: order_by +} + """aggregate stddev_samp on columns""" type shorturls_stddev_samp_fields { clicks: Float } +""" +order by stddev_samp() on columns of table "shorturls" +""" +input shorturls_stddev_samp_order_by { + clicks: order_by +} + """ Streaming cursor of the table "shorturls" """ @@ -1372,6 +1706,13 @@ type shorturls_sum_fields { clicks: Int } +""" +order by sum() on columns of table "shorturls" +""" +input shorturls_sum_order_by { + clicks: order_by +} + """ update columns of table "shorturls" """ @@ -1414,16 +1755,37 @@ type shorturls_var_pop_fields { clicks: Float } +""" +order by var_pop() on columns of table "shorturls" +""" +input shorturls_var_pop_order_by { + clicks: order_by +} + """aggregate var_samp on columns""" type shorturls_var_samp_fields { clicks: Float } +""" +order by var_samp() on columns of table "shorturls" +""" +input shorturls_var_samp_order_by { + clicks: order_by +} + """aggregate variance on columns""" type shorturls_variance_fields { clicks: Float } +""" +order by variance() on columns of table "shorturls" +""" +input shorturls_variance_order_by { + clicks: order_by +} + type subscription_root { """ fetch data from the table: "apikeys" @@ -1482,9 +1844,7 @@ type subscription_root { where: apikeys_bool_exp ): [apikeys!]! - """ - fetch data from the table: "gists" - """ + """An array relationship""" gists( """distinct select on columns""" distinct_on: [gists_select_column!] @@ -1502,9 +1862,7 @@ type subscription_root { where: gists_bool_exp ): [gists!]! - """ - fetch aggregated fields from the table: "gists" - """ + """An aggregate relationship""" gists_aggregate( """distinct select on columns""" distinct_on: [gists_select_column!] @@ -1539,9 +1897,7 @@ type subscription_root { where: gists_bool_exp ): [gists!]! - """ - fetch data from the table: "shorturls" - """ + """An array relationship""" shorturls( """distinct select on columns""" distinct_on: [shorturls_select_column!] @@ -1559,9 +1915,7 @@ type subscription_root { where: shorturls_bool_exp ): [shorturls!]! - """ - fetch aggregated fields from the table: "shorturls" - """ + """An aggregate relationship""" shorturls_aggregate( """distinct select on columns""" distinct_on: [shorturls_select_column!] diff --git a/hasura/config.yaml b/packages/api/hasura/config.yaml similarity index 100% rename from hasura/config.yaml rename to packages/api/hasura/config.yaml diff --git a/hasura/metadata/actions.graphql b/packages/api/hasura/metadata/actions.graphql similarity index 100% rename from hasura/metadata/actions.graphql rename to packages/api/hasura/metadata/actions.graphql diff --git a/hasura/metadata/actions.yaml b/packages/api/hasura/metadata/actions.yaml similarity index 100% rename from hasura/metadata/actions.yaml rename to packages/api/hasura/metadata/actions.yaml diff --git a/hasura/metadata/allow_list.yaml b/packages/api/hasura/metadata/allow_list.yaml similarity index 100% rename from hasura/metadata/allow_list.yaml rename to packages/api/hasura/metadata/allow_list.yaml diff --git a/hasura/metadata/api_limits.yaml b/packages/api/hasura/metadata/api_limits.yaml similarity index 100% rename from hasura/metadata/api_limits.yaml rename to packages/api/hasura/metadata/api_limits.yaml diff --git a/hasura/metadata/backend_configs.yaml b/packages/api/hasura/metadata/backend_configs.yaml similarity index 100% rename from hasura/metadata/backend_configs.yaml rename to packages/api/hasura/metadata/backend_configs.yaml diff --git a/hasura/metadata/cron_triggers.yaml b/packages/api/hasura/metadata/cron_triggers.yaml similarity index 100% rename from hasura/metadata/cron_triggers.yaml rename to packages/api/hasura/metadata/cron_triggers.yaml diff --git a/hasura/metadata/databases/databases.yaml b/packages/api/hasura/metadata/databases/databases.yaml similarity index 100% rename from hasura/metadata/databases/databases.yaml rename to packages/api/hasura/metadata/databases/databases.yaml diff --git a/hasura/metadata/databases/default/tables/public_apikeys.yaml b/packages/api/hasura/metadata/databases/default/tables/public_apikeys.yaml similarity index 100% rename from hasura/metadata/databases/default/tables/public_apikeys.yaml rename to packages/api/hasura/metadata/databases/default/tables/public_apikeys.yaml diff --git a/hasura/metadata/databases/default/tables/public_gists.yaml b/packages/api/hasura/metadata/databases/default/tables/public_gists.yaml similarity index 100% rename from hasura/metadata/databases/default/tables/public_gists.yaml rename to packages/api/hasura/metadata/databases/default/tables/public_gists.yaml diff --git a/hasura/metadata/databases/default/tables/public_shorturls.yaml b/packages/api/hasura/metadata/databases/default/tables/public_shorturls.yaml similarity index 100% rename from hasura/metadata/databases/default/tables/public_shorturls.yaml rename to packages/api/hasura/metadata/databases/default/tables/public_shorturls.yaml diff --git a/hasura/metadata/databases/default/tables/public_uploads.yaml b/packages/api/hasura/metadata/databases/default/tables/public_uploads.yaml similarity index 100% rename from hasura/metadata/databases/default/tables/public_uploads.yaml rename to packages/api/hasura/metadata/databases/default/tables/public_uploads.yaml diff --git a/hasura/metadata/databases/default/tables/tables.yaml b/packages/api/hasura/metadata/databases/default/tables/tables.yaml similarity index 100% rename from hasura/metadata/databases/default/tables/tables.yaml rename to packages/api/hasura/metadata/databases/default/tables/tables.yaml diff --git a/hasura/metadata/graphql_schema_introspection.yaml b/packages/api/hasura/metadata/graphql_schema_introspection.yaml similarity index 100% rename from hasura/metadata/graphql_schema_introspection.yaml rename to packages/api/hasura/metadata/graphql_schema_introspection.yaml diff --git a/hasura/metadata/inherited_roles.yaml b/packages/api/hasura/metadata/inherited_roles.yaml similarity index 100% rename from hasura/metadata/inherited_roles.yaml rename to packages/api/hasura/metadata/inherited_roles.yaml diff --git a/hasura/metadata/metrics_config.yaml b/packages/api/hasura/metadata/metrics_config.yaml similarity index 100% rename from hasura/metadata/metrics_config.yaml rename to packages/api/hasura/metadata/metrics_config.yaml diff --git a/hasura/metadata/network.yaml b/packages/api/hasura/metadata/network.yaml similarity index 100% rename from hasura/metadata/network.yaml rename to packages/api/hasura/metadata/network.yaml diff --git a/hasura/metadata/opentelemetry.yaml b/packages/api/hasura/metadata/opentelemetry.yaml similarity index 100% rename from hasura/metadata/opentelemetry.yaml rename to packages/api/hasura/metadata/opentelemetry.yaml diff --git a/hasura/metadata/query_collections.yaml b/packages/api/hasura/metadata/query_collections.yaml similarity index 100% rename from hasura/metadata/query_collections.yaml rename to packages/api/hasura/metadata/query_collections.yaml diff --git a/hasura/metadata/remote_schemas.yaml b/packages/api/hasura/metadata/remote_schemas.yaml similarity index 100% rename from hasura/metadata/remote_schemas.yaml rename to packages/api/hasura/metadata/remote_schemas.yaml diff --git a/hasura/metadata/rest_endpoints.yaml b/packages/api/hasura/metadata/rest_endpoints.yaml similarity index 100% rename from hasura/metadata/rest_endpoints.yaml rename to packages/api/hasura/metadata/rest_endpoints.yaml diff --git a/hasura/metadata/version.yaml b/packages/api/hasura/metadata/version.yaml similarity index 100% rename from hasura/metadata/version.yaml rename to packages/api/hasura/metadata/version.yaml diff --git a/hasura/migrations/default/1683384792406_generate_api_key_func/down.sql b/packages/api/hasura/migrations/default/1683384792406_generate_api_key_func/down.sql similarity index 100% rename from hasura/migrations/default/1683384792406_generate_api_key_func/down.sql rename to packages/api/hasura/migrations/default/1683384792406_generate_api_key_func/down.sql diff --git a/hasura/migrations/default/1683384792406_generate_api_key_func/up.sql b/packages/api/hasura/migrations/default/1683384792406_generate_api_key_func/up.sql similarity index 100% rename from hasura/migrations/default/1683384792406_generate_api_key_func/up.sql rename to packages/api/hasura/migrations/default/1683384792406_generate_api_key_func/up.sql diff --git a/hasura/migrations/default/1683384939518_create_table_public_apikeys/down.sql b/packages/api/hasura/migrations/default/1683384939518_create_table_public_apikeys/down.sql similarity index 100% rename from hasura/migrations/default/1683384939518_create_table_public_apikeys/down.sql rename to packages/api/hasura/migrations/default/1683384939518_create_table_public_apikeys/down.sql diff --git a/hasura/migrations/default/1683384939518_create_table_public_apikeys/up.sql b/packages/api/hasura/migrations/default/1683384939518_create_table_public_apikeys/up.sql similarity index 100% rename from hasura/migrations/default/1683384939518_create_table_public_apikeys/up.sql rename to packages/api/hasura/migrations/default/1683384939518_create_table_public_apikeys/up.sql diff --git a/hasura/migrations/default/1683385211855_create_table_public_uploads/down.sql b/packages/api/hasura/migrations/default/1683385211855_create_table_public_uploads/down.sql similarity index 100% rename from hasura/migrations/default/1683385211855_create_table_public_uploads/down.sql rename to packages/api/hasura/migrations/default/1683385211855_create_table_public_uploads/down.sql diff --git a/hasura/migrations/default/1683385211855_create_table_public_uploads/up.sql b/packages/api/hasura/migrations/default/1683385211855_create_table_public_uploads/up.sql similarity index 100% rename from hasura/migrations/default/1683385211855_create_table_public_uploads/up.sql rename to packages/api/hasura/migrations/default/1683385211855_create_table_public_uploads/up.sql diff --git a/hasura/migrations/default/1683385486210_run_sql_migration/down.sql b/packages/api/hasura/migrations/default/1683385486210_run_sql_migration/down.sql similarity index 100% rename from hasura/migrations/default/1683385486210_run_sql_migration/down.sql rename to packages/api/hasura/migrations/default/1683385486210_run_sql_migration/down.sql diff --git a/hasura/migrations/default/1683385486210_run_sql_migration/up.sql b/packages/api/hasura/migrations/default/1683385486210_run_sql_migration/up.sql similarity index 100% rename from hasura/migrations/default/1683385486210_run_sql_migration/up.sql rename to packages/api/hasura/migrations/default/1683385486210_run_sql_migration/up.sql diff --git a/hasura/migrations/default/1683385777576_run_sql_migration/down.sql b/packages/api/hasura/migrations/default/1683385777576_run_sql_migration/down.sql similarity index 100% rename from hasura/migrations/default/1683385777576_run_sql_migration/down.sql rename to packages/api/hasura/migrations/default/1683385777576_run_sql_migration/down.sql diff --git a/hasura/migrations/default/1683385777576_run_sql_migration/up.sql b/packages/api/hasura/migrations/default/1683385777576_run_sql_migration/up.sql similarity index 100% rename from hasura/migrations/default/1683385777576_run_sql_migration/up.sql rename to packages/api/hasura/migrations/default/1683385777576_run_sql_migration/up.sql diff --git a/hasura/migrations/default/1683386226447_run_sql_migration/down.sql b/packages/api/hasura/migrations/default/1683386226447_run_sql_migration/down.sql similarity index 100% rename from hasura/migrations/default/1683386226447_run_sql_migration/down.sql rename to packages/api/hasura/migrations/default/1683386226447_run_sql_migration/down.sql diff --git a/hasura/migrations/default/1683386226447_run_sql_migration/up.sql b/packages/api/hasura/migrations/default/1683386226447_run_sql_migration/up.sql similarity index 100% rename from hasura/migrations/default/1683386226447_run_sql_migration/up.sql rename to packages/api/hasura/migrations/default/1683386226447_run_sql_migration/up.sql diff --git a/hasura/migrations/default/1683386282101_run_sql_migration/down.sql b/packages/api/hasura/migrations/default/1683386282101_run_sql_migration/down.sql similarity index 100% rename from hasura/migrations/default/1683386282101_run_sql_migration/down.sql rename to packages/api/hasura/migrations/default/1683386282101_run_sql_migration/down.sql diff --git a/hasura/migrations/default/1683386282101_run_sql_migration/up.sql b/packages/api/hasura/migrations/default/1683386282101_run_sql_migration/up.sql similarity index 100% rename from hasura/migrations/default/1683386282101_run_sql_migration/up.sql rename to packages/api/hasura/migrations/default/1683386282101_run_sql_migration/up.sql diff --git a/hasura/migrations/default/1683386346978_run_sql_migration/down.sql b/packages/api/hasura/migrations/default/1683386346978_run_sql_migration/down.sql similarity index 100% rename from hasura/migrations/default/1683386346978_run_sql_migration/down.sql rename to packages/api/hasura/migrations/default/1683386346978_run_sql_migration/down.sql diff --git a/hasura/migrations/default/1683386346978_run_sql_migration/up.sql b/packages/api/hasura/migrations/default/1683386346978_run_sql_migration/up.sql similarity index 100% rename from hasura/migrations/default/1683386346978_run_sql_migration/up.sql rename to packages/api/hasura/migrations/default/1683386346978_run_sql_migration/up.sql diff --git a/hasura/migrations/default/1683386492737_run_sql_migration/down.sql b/packages/api/hasura/migrations/default/1683386492737_run_sql_migration/down.sql similarity index 100% rename from hasura/migrations/default/1683386492737_run_sql_migration/down.sql rename to packages/api/hasura/migrations/default/1683386492737_run_sql_migration/down.sql diff --git a/hasura/migrations/default/1683386492737_run_sql_migration/up.sql b/packages/api/hasura/migrations/default/1683386492737_run_sql_migration/up.sql similarity index 100% rename from hasura/migrations/default/1683386492737_run_sql_migration/up.sql rename to packages/api/hasura/migrations/default/1683386492737_run_sql_migration/up.sql diff --git a/hasura/migrations/default/1683386905959_create_table_public_shorturls/down.sql b/packages/api/hasura/migrations/default/1683386905959_create_table_public_shorturls/down.sql similarity index 100% rename from hasura/migrations/default/1683386905959_create_table_public_shorturls/down.sql rename to packages/api/hasura/migrations/default/1683386905959_create_table_public_shorturls/down.sql diff --git a/hasura/migrations/default/1683386905959_create_table_public_shorturls/up.sql b/packages/api/hasura/migrations/default/1683386905959_create_table_public_shorturls/up.sql similarity index 100% rename from hasura/migrations/default/1683386905959_create_table_public_shorturls/up.sql rename to packages/api/hasura/migrations/default/1683386905959_create_table_public_shorturls/up.sql diff --git a/hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/down.sql b/packages/api/hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/down.sql similarity index 100% rename from hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/down.sql rename to packages/api/hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/down.sql diff --git a/hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/up.sql b/packages/api/hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/up.sql similarity index 100% rename from hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/up.sql rename to packages/api/hasura/migrations/default/1683386943002_alter_table_public_shorturls_alter_column_creater_ip/up.sql diff --git a/hasura/migrations/default/1683387751628_create_table_public_gists/down.sql b/packages/api/hasura/migrations/default/1683387751628_create_table_public_gists/down.sql similarity index 100% rename from hasura/migrations/default/1683387751628_create_table_public_gists/down.sql rename to packages/api/hasura/migrations/default/1683387751628_create_table_public_gists/down.sql diff --git a/hasura/migrations/default/1683387751628_create_table_public_gists/up.sql b/packages/api/hasura/migrations/default/1683387751628_create_table_public_gists/up.sql similarity index 100% rename from hasura/migrations/default/1683387751628_create_table_public_gists/up.sql rename to packages/api/hasura/migrations/default/1683387751628_create_table_public_gists/up.sql diff --git a/hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/down.sql b/packages/api/hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/down.sql similarity index 100% rename from hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/down.sql rename to packages/api/hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/down.sql diff --git a/hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/up.sql b/packages/api/hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/up.sql similarity index 100% rename from hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/up.sql rename to packages/api/hasura/migrations/default/1683387777285_alter_table_public_gists_alter_column_gist_url_key/up.sql diff --git a/helpers/axios_client.ts b/packages/api/helpers/axios_client.ts similarity index 99% rename from helpers/axios_client.ts rename to packages/api/helpers/axios_client.ts index ff9ffab..ab93c0e 100644 --- a/helpers/axios_client.ts +++ b/packages/api/helpers/axios_client.ts @@ -28,4 +28,4 @@ axiosInstance.interceptors.response.use( newError.config.metadata.endTime - newError.config.metadata.startTime; return Promise.reject(newError); } -); \ No newline at end of file +); diff --git a/helpers/cache.factory.ts b/packages/api/helpers/cache.factory.ts similarity index 100% rename from helpers/cache.factory.ts rename to packages/api/helpers/cache.factory.ts diff --git a/helpers/gql_clent.ts b/packages/api/helpers/gql_clent.ts similarity index 100% rename from helpers/gql_clent.ts rename to packages/api/helpers/gql_clent.ts diff --git a/helpers/index.ts b/packages/api/helpers/index.ts similarity index 73% rename from helpers/index.ts rename to packages/api/helpers/index.ts index 4e36b92..3b531d1 100644 --- a/helpers/index.ts +++ b/packages/api/helpers/index.ts @@ -1,4 +1,4 @@ export * from './cache.factory'; export * from './gql_clent'; export * from './axios_client'; -export * from './upload.factory' \ No newline at end of file +export * from './upload.factory'; diff --git a/helpers/upload.factory.ts b/packages/api/helpers/upload.factory.ts similarity index 100% rename from helpers/upload.factory.ts rename to packages/api/helpers/upload.factory.ts diff --git a/index.ts b/packages/api/index.ts similarity index 96% rename from index.ts rename to packages/api/index.ts index 9ad4372..6ed508d 100644 --- a/index.ts +++ b/packages/api/index.ts @@ -5,7 +5,6 @@ import morgan from 'morgan'; import helmet from 'helmet'; import { hgqlInit } from './helpers'; -import routes from './routes'; import { errorHandler, notFoundHandler } from './libs'; import pkg from './package.json' assert { type: 'json' }; import configStore from './configs'; @@ -22,6 +21,10 @@ const configs = new configStore(isDev); const configKeys = await configs.getConfigStore(); const urlStoreController = new URLStoreController(); +console.log('🔑', 'Master Key', configKeys.MASTER_KEY); + +import routes from './routes'; + hgqlInit(); CacheClient.init(configKeys.CACHE_ENV as CacheEnvironment); diff --git a/interfaces/apikey.interface.d.ts b/packages/api/interfaces/apikey.interface.d.ts similarity index 100% rename from interfaces/apikey.interface.d.ts rename to packages/api/interfaces/apikey.interface.d.ts diff --git a/interfaces/config.interface.d.ts b/packages/api/interfaces/config.interface.d.ts similarity index 100% rename from interfaces/config.interface.d.ts rename to packages/api/interfaces/config.interface.d.ts diff --git a/interfaces/gists.interface.d.ts b/packages/api/interfaces/gists.interface.d.ts similarity index 100% rename from interfaces/gists.interface.d.ts rename to packages/api/interfaces/gists.interface.d.ts diff --git a/interfaces/sxcu.interface.d.ts b/packages/api/interfaces/sxcu.interface.d.ts similarity index 100% rename from interfaces/sxcu.interface.d.ts rename to packages/api/interfaces/sxcu.interface.d.ts diff --git a/interfaces/upload.interface.d.ts b/packages/api/interfaces/upload.interface.d.ts similarity index 100% rename from interfaces/upload.interface.d.ts rename to packages/api/interfaces/upload.interface.d.ts diff --git a/interfaces/urlstore.interface.d.ts b/packages/api/interfaces/urlstore.interface.d.ts similarity index 100% rename from interfaces/urlstore.interface.d.ts rename to packages/api/interfaces/urlstore.interface.d.ts diff --git a/libs/customErrHandler.ts b/packages/api/libs/customErrHandler.ts similarity index 100% rename from libs/customErrHandler.ts rename to packages/api/libs/customErrHandler.ts diff --git a/libs/error.ts b/packages/api/libs/error.ts similarity index 100% rename from libs/error.ts rename to packages/api/libs/error.ts diff --git a/libs/index.ts b/packages/api/libs/index.ts similarity index 100% rename from libs/index.ts rename to packages/api/libs/index.ts diff --git a/libs/middleware.ts b/packages/api/libs/middleware.ts similarity index 97% rename from libs/middleware.ts rename to packages/api/libs/middleware.ts index 9141ec4..845e2ac 100644 --- a/libs/middleware.ts +++ b/packages/api/libs/middleware.ts @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express'; import Joi from 'joi'; import { CustomError, NotFoundError } from './error'; import { pick } from './utilities'; -import { configKeys } from ".." +import { configKeys } from '..'; export const errorHandler = async ( err: any, @@ -58,7 +58,7 @@ export const validate = }) ); } - + Object.assign(req, value); return next(); diff --git a/libs/utilities.ts b/packages/api/libs/utilities.ts similarity index 99% rename from libs/utilities.ts rename to packages/api/libs/utilities.ts index 401cd60..e268c4c 100644 --- a/libs/utilities.ts +++ b/packages/api/libs/utilities.ts @@ -142,4 +142,4 @@ export const getSortColumn = ( export const is_uuid = (value: string) => { const regex = /^()/; return regex.test(value); -}; \ No newline at end of file +}; diff --git a/middlewares/apikey_check.ts b/packages/api/middlewares/apikey_check.ts similarity index 100% rename from middlewares/apikey_check.ts rename to packages/api/middlewares/apikey_check.ts diff --git a/packages/api/package.json b/packages/api/package.json new file mode 100644 index 0000000..96e9af3 --- /dev/null +++ b/packages/api/package.json @@ -0,0 +1,66 @@ +{ + "name": "shx-api", + "version": "1.0.0", + "description": "My ShareX Server acting as Daddy", + "main": "index.ts", + "repository": "https://github.com/bravo68web/shx.git", + "author": { + "email": "hi@b68.dev", + "name": "Jyotirmoy Bandyopadhayaya", + "url": "https://b68.dev" + }, + "license": "ISC", + "type": "module", + "private": true, + "dependencies": { + "@aws-sdk/client-s3": "^3.226.0", + "axios": "^1.2.1", + "cors": "^2.8.5", + "dotenv": "^16.0.3", + "envfile": "^6.18.0", + "express": "^4.18.2", + "form-data": "^4.0.0", + "graphql": "^16.6.0", + "graphql-request": "^5.0.0", + "helmet": "^6.0.1", + "joi": "^17.7.0", + "morgan": "^1.10.0", + "multer": "^1.4.5-lts.1", + "multer-s3": "^3.0.1", + "napi-nanoid": "^0.0.4", + "node-cache": "^5.1.2", + "nodemailer": "^6.8.0", + "redis": "^4.5.1", + "sharp": "^0.32.1" + }, + "scripts": { + "dev": "concurrently \"npm run dev:express\" \"npm run dev:hasura\"", + "dev:hasura": "cd hasura && hasura --skip-update-check --envfile ../.env console", + "dev:express": "cross-env NODE_ENV=development nodemon -x node --no-warnings --experimental-specifier-resolution=node --loader ts-node/esm index.ts --signal SIGKILL --ignore node_modules", + "build": "tsc -p tsconfig.json", + "start": "node --es-module-specifier-resolution=node --loader ts-node/esm ./build/index.js", + "fetch:schemas": "bash bin/fetch-gql-schema.sh" + }, + "devDependencies": { + "@swc/core": "^1.3.23", + "@swc/wasm": "^1.3.23", + "@types/cors": "^2.8.13", + "@types/express": "^4.17.14", + "@types/morgan": "^1.9.3", + "@types/multer": "^1.4.7", + "@typescript-eslint/eslint-plugin": "^5.54.1", + "@typescript-eslint/parser": "^5.54.1", + "concurrently": "^7.6.0", + "cross-env": "^7.0.3", + "eslint": "^8.35.0", + "eslint-config-prettier": "^8.7.0", + "graphqurl": "^1.0.1", + "hasura-cli": "^2.15.1", + "husky": "^8.0.3", + "lint-staged": "^13.1.2", + "nodemon": "^2.0.22", + "prettier": "^2.8.2", + "ts-node": "^10.9.1", + "typescript": "^4.9.3" + } +} diff --git a/routes/apikey.routes.ts b/packages/api/routes/apikey.routes.ts similarity index 100% rename from routes/apikey.routes.ts rename to packages/api/routes/apikey.routes.ts diff --git a/routes/config.routes.ts b/packages/api/routes/config.routes.ts similarity index 100% rename from routes/config.routes.ts rename to packages/api/routes/config.routes.ts diff --git a/routes/gist.routes.ts b/packages/api/routes/gist.routes.ts similarity index 100% rename from routes/gist.routes.ts rename to packages/api/routes/gist.routes.ts diff --git a/routes/index.ts b/packages/api/routes/index.ts similarity index 93% rename from routes/index.ts rename to packages/api/routes/index.ts index 408db0d..b4eb733 100644 --- a/routes/index.ts +++ b/packages/api/routes/index.ts @@ -31,7 +31,10 @@ const loadRoutes = async (dirPath: string, prefix = '/') => { router.use(modRoute, mod.default); } } else if (f.isDirectory()) { - await loadRoutes(path.resolve(dirPath, f.name), prefix + f.name + '/'); + await loadRoutes( + path.resolve(dirPath, f.name), + path.join(prefix, f.name, '/') + ); } }); }; diff --git a/routes/upload.routes.ts b/packages/api/routes/upload.routes.ts similarity index 100% rename from routes/upload.routes.ts rename to packages/api/routes/upload.routes.ts diff --git a/routes/url.routes.ts b/packages/api/routes/url.routes.ts similarity index 100% rename from routes/url.routes.ts rename to packages/api/routes/url.routes.ts diff --git a/services/apikey.service.ts b/packages/api/services/apikey.service.ts similarity index 98% rename from services/apikey.service.ts rename to packages/api/services/apikey.service.ts index 55b6b87..481e1ef 100644 --- a/services/apikey.service.ts +++ b/packages/api/services/apikey.service.ts @@ -57,7 +57,6 @@ export default class APIKeyService implements IAPIKeyService { } public async listS(masterKey: string): Promise { - console.log(masterKey); if (masterKey !== configKeys.MASTER_KEY) throw new Error('Invalid master key'); const query = gql` diff --git a/services/gist.service.ts b/packages/api/services/gist.service.ts similarity index 100% rename from services/gist.service.ts rename to packages/api/services/gist.service.ts diff --git a/services/sxcu.service.ts b/packages/api/services/sxcu.service.ts similarity index 100% rename from services/sxcu.service.ts rename to packages/api/services/sxcu.service.ts diff --git a/services/upload.service.ts b/packages/api/services/upload.service.ts similarity index 94% rename from services/upload.service.ts rename to packages/api/services/upload.service.ts index b734f48..753252f 100644 --- a/services/upload.service.ts +++ b/packages/api/services/upload.service.ts @@ -9,11 +9,15 @@ import axios from 'axios'; import fs from 'fs'; import { nanoid } from 'napi-nanoid'; -const uploaderService = new UploaderService(configKeys.R2_BUCKET_NAME); - export default class Uploader implements IUploaderService { + uploaderService: UploaderService; + + constructor() { + this.uploaderService = new UploaderService(configKeys.R2_BUCKET_NAME); + } + public uploadS = async (file: any, meta: UserMeta) => { - await uploaderService.uploadFile( + await this.uploaderService.uploadFile( configKeys.R2_BUCKET_FOLDER!, file.newName, file.buffer, @@ -56,7 +60,7 @@ export default class Uploader implements IUploaderService { const image: any = sharp(file.buffer); await image.toFormat('jpeg'); const buffer: any = await image.toBuffer(); - await uploaderService.uploadFile( + await this.uploaderService.uploadFile( configKeys.R2_BUCKET_FOLDER!, file.newName, buffer, @@ -102,7 +106,7 @@ export default class Uploader implements IUploaderService { const image: any = sharp(rawImage); await image.toFormat('jpeg'); const buffer: any = await image.toBuffer(); - await uploaderService.uploadFile( + await this.uploaderService.uploadFile( configKeys.R2_BUCKET_FOLDER!, filename, buffer, @@ -167,7 +171,7 @@ export default class Uploader implements IUploaderService { public uploadFileViaURLS = async (url: string, meta: UserMeta) => { const filename = await this.downloadFile(url); - await uploaderService.uploadFile( + await this.uploaderService.uploadFile( configKeys.R2_BUCKET_FOLDER!, filename, fs.readFileSync(`uploads/${filename}`), diff --git a/services/urlstore.service.ts b/packages/api/services/urlstore.service.ts similarity index 100% rename from services/urlstore.service.ts rename to packages/api/services/urlstore.service.ts diff --git a/tsconfig.json b/packages/api/tsconfig.json similarity index 67% rename from tsconfig.json rename to packages/api/tsconfig.json index 0ec745e..8c33452 100644 --- a/tsconfig.json +++ b/packages/api/tsconfig.json @@ -1,22 +1,22 @@ { "compilerOptions": { "lib": ["es2018", "es5", "dom"], - "typeRoots": ["node_modules/@types", "./types"], + "typeRoots": ["node_modules/@types", "types"], "resolveJsonModule": true, "esModuleInterop": true, "target": "ES2017", "strict": true, "module": "ESNext", "moduleResolution": "node", - "outDir": "./build", + "outDir": "build", "emitDecoratorMetadata": true, "experimentalDecorators": true, "declaration": true, "sourceMap": false, "noImplicitAny": false }, - "exclude": ["./node_modules/**/*", "./build/**/*"], - "include": ["./**/*.ts", "./**/*.tsx", "./**/*.json", "./**/*.js"], + "exclude": ["node_modules/**/*", "build/**/*"], + "include": ["**/*.ts", "**/*.tsx", "**/*.json", "**/*.js"], "ts-node": { "swc": true }, diff --git a/types/index.d.ts b/packages/api/types/index.d.ts similarity index 100% rename from types/index.d.ts rename to packages/api/types/index.d.ts diff --git a/uploads/.gitkeep b/packages/api/uploads/.gitkeep similarity index 100% rename from uploads/.gitkeep rename to packages/api/uploads/.gitkeep diff --git a/packages/api/uploads/_7Igi_nHGwQ0vRScphQ1IIpfs-logo-1024-ice-text.png b/packages/api/uploads/_7Igi_nHGwQ0vRScphQ1IIpfs-logo-1024-ice-text.png new file mode 100644 index 0000000..27a8262 Binary files /dev/null and b/packages/api/uploads/_7Igi_nHGwQ0vRScphQ1IIpfs-logo-1024-ice-text.png differ diff --git a/packages/cli/package.json b/packages/cli/package.json new file mode 100644 index 0000000..9749a13 --- /dev/null +++ b/packages/cli/package.json @@ -0,0 +1,27 @@ +{ + "name": "shx-cli", + "version": "1.0.0", + "description": "CLI Utility for SHX API", + "main": "build/src/shx.js", + "author": "BRAVO68WEB", + "license": "MIT", + "private": true, + "devDependencies": { + "@types/node": "^20.1.5", + "typescript": "^5.0.4" + }, + "dependencies": { + "axios": "^1.4.0", + "commander": "^10.0.1", + "configstore": "^6.0.0" + }, + "scripts": { + "i:g": "npm i -g .", + "u:g": "npm uninstall -g shx-cli", + "build": "tsc", + "r": "npm run u:g && npm run build && npm run i:g" + }, + "bin": { + "shx": "./build/src/shx.js" + } +} diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts new file mode 100644 index 0000000..4777324 --- /dev/null +++ b/packages/cli/src/commands/index.ts @@ -0,0 +1,12 @@ +import { Command } from 'commander'; +import infoCMD from './info'; + +export class loadCommads { + constructor(program: Command) { + this.info(program); + } + + public info = (program: Command) => { + return infoCMD(program); + }; +} diff --git a/packages/cli/src/commands/info.ts b/packages/cli/src/commands/info.ts new file mode 100644 index 0000000..41b61ed --- /dev/null +++ b/packages/cli/src/commands/info.ts @@ -0,0 +1,11 @@ +import { Command } from 'commander'; +import infoFn from '../functions/info'; + +export default (program: Command) => { + return program + .command('info') + .description('Show info about the CLI') + .action(() => { + infoFn(); + }); +}; diff --git a/packages/cli/src/functions/info.ts b/packages/cli/src/functions/info.ts new file mode 100644 index 0000000..4ce4557 --- /dev/null +++ b/packages/cli/src/functions/info.ts @@ -0,0 +1,4 @@ +export default () => { + console.log('This is the CLI for SHX API !!'); + return; +}; diff --git a/packages/cli/src/shx.ts b/packages/cli/src/shx.ts new file mode 100644 index 0000000..59a72a1 --- /dev/null +++ b/packages/cli/src/shx.ts @@ -0,0 +1,9 @@ +#!/usr/bin/env node +import { Command } from 'commander'; +import { loadCommads } from './commands'; + +const program = new Command(); + +new loadCommads(program); + +program.parse(process.argv); diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json new file mode 100644 index 0000000..7fa1652 --- /dev/null +++ b/packages/cli/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "lib": ["es2018", "es5", "dom"], + "typeRoots": ["node_modules/@types", "types"], + "resolveJsonModule": true, + "esModuleInterop": true, + "target": "ES2017", + "strict": true, + "module": "commonjs", + "moduleResolution": "node", + "outDir": "build", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "declaration": true, + "sourceMap": false, + "noImplicitAny": false, + "types": ["node"] + }, + "exclude": ["node_modules/**/*", "build/**/*"], + "include": ["**/*.ts", "**/*.tsx", "**/*.json", "**/*.js"], + "ts-node": { + "swc": true + }, +} diff --git a/packages/frontend/.eslintrc.json b/packages/frontend/.eslintrc.json new file mode 100644 index 0000000..bffb357 --- /dev/null +++ b/packages/frontend/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "next/core-web-vitals" +} diff --git a/packages/frontend/.gitignore b/packages/frontend/.gitignore new file mode 100644 index 0000000..8f322f0 --- /dev/null +++ b/packages/frontend/.gitignore @@ -0,0 +1,35 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/packages/frontend/README.md b/packages/frontend/README.md new file mode 100644 index 0000000..965a122 --- /dev/null +++ b/packages/frontend/README.md @@ -0,0 +1,38 @@ +This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). + +## Getting Started + +First, run the development server: + +```bash +npm run dev +# or +yarn dev +# or +pnpm dev +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. + +[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. + +The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. + +This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. + +## Learn More + +To learn more about Next.js, take a look at the following resources: + +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. + +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! + +## Deploy on Vercel + +The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/packages/frontend/next.config.js b/packages/frontend/next.config.js new file mode 100644 index 0000000..7ca34f0 --- /dev/null +++ b/packages/frontend/next.config.js @@ -0,0 +1,6 @@ +/** @type {import('next').NextConfig} */ +const nextConfig = { + reactStrictMode: true, +}; + +module.exports = nextConfig; diff --git a/packages/frontend/package.json b/packages/frontend/package.json new file mode 100644 index 0000000..40b87e6 --- /dev/null +++ b/packages/frontend/package.json @@ -0,0 +1,25 @@ +{ + "name": "frontend", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "next lint" + }, + "dependencies": { + "@types/node": "20.1.5", + "@types/react": "18.2.6", + "@types/react-dom": "18.2.4", + "autoprefixer": "10.4.14", + "eslint": "8.40.0", + "eslint-config-next": "13.4.2", + "next": "13.4.2", + "postcss": "8.4.23", + "react": "18.2.0", + "react-dom": "18.2.0", + "tailwindcss": "3.3.2", + "typescript": "5.0.4" + } +} diff --git a/packages/frontend/pages/_app.tsx b/packages/frontend/pages/_app.tsx new file mode 100644 index 0000000..3b2235d --- /dev/null +++ b/packages/frontend/pages/_app.tsx @@ -0,0 +1,6 @@ +import '/styles/globals.css' +import type { AppProps } from 'next/app' + +export default function App({ Component, pageProps }: AppProps) { + return +} diff --git a/packages/frontend/pages/_document.tsx b/packages/frontend/pages/_document.tsx new file mode 100644 index 0000000..54e8bf3 --- /dev/null +++ b/packages/frontend/pages/_document.tsx @@ -0,0 +1,13 @@ +import { Html, Head, Main, NextScript } from 'next/document' + +export default function Document() { + return ( + + + +
+ + + + ) +} diff --git a/packages/frontend/pages/api/hello.ts b/packages/frontend/pages/api/hello.ts new file mode 100644 index 0000000..5b60947 --- /dev/null +++ b/packages/frontend/pages/api/hello.ts @@ -0,0 +1,13 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import type { NextApiRequest, NextApiResponse } from 'next'; + +type Data = { + name: string; +}; + +export default function handler( + req: NextApiRequest, + res: NextApiResponse +) { + res.status(200).json({ name: 'John Doe' }); +} diff --git a/packages/frontend/pages/index.tsx b/packages/frontend/pages/index.tsx new file mode 100644 index 0000000..14f2678 --- /dev/null +++ b/packages/frontend/pages/index.tsx @@ -0,0 +1,118 @@ +import Image from 'next/image' +import { Inter } from 'next/font/google' + +const inter = Inter({ subsets: ['latin'] }) + +export default function Home() { + return ( +
+
+

+ Get started by editing  + pages/index.tsx +

+ +
+ +
+ Next.js Logo +
+ + +
+ ) +} diff --git a/packages/frontend/postcss.config.js b/packages/frontend/postcss.config.js new file mode 100644 index 0000000..e873f1a --- /dev/null +++ b/packages/frontend/postcss.config.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; diff --git a/packages/frontend/public/favicon.ico b/packages/frontend/public/favicon.ico new file mode 100644 index 0000000..4570eb8 Binary files /dev/null and b/packages/frontend/public/favicon.ico differ diff --git a/packages/frontend/public/next.svg b/packages/frontend/public/next.svg new file mode 100644 index 0000000..5174b28 --- /dev/null +++ b/packages/frontend/public/next.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/frontend/public/vercel.svg b/packages/frontend/public/vercel.svg new file mode 100644 index 0000000..d2f8422 --- /dev/null +++ b/packages/frontend/public/vercel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/frontend/styles/globals.css b/packages/frontend/styles/globals.css new file mode 100644 index 0000000..fd81e88 --- /dev/null +++ b/packages/frontend/styles/globals.css @@ -0,0 +1,27 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +:root { + --foreground-rgb: 0, 0, 0; + --background-start-rgb: 214, 219, 220; + --background-end-rgb: 255, 255, 255; +} + +@media (prefers-color-scheme: dark) { + :root { + --foreground-rgb: 255, 255, 255; + --background-start-rgb: 0, 0, 0; + --background-end-rgb: 0, 0, 0; + } +} + +body { + color: rgb(var(--foreground-rgb)); + background: linear-gradient( + to bottom, + transparent, + rgb(var(--background-end-rgb)) + ) + rgb(var(--background-start-rgb)); +} diff --git a/packages/frontend/tailwind.config.js b/packages/frontend/tailwind.config.js new file mode 100644 index 0000000..0dceef8 --- /dev/null +++ b/packages/frontend/tailwind.config.js @@ -0,0 +1,18 @@ +/** @type {import('tailwindcss').Config} */ +module.exports = { + content: [ + './pages/**/*.{js,ts,jsx,tsx,mdx}', + './components/**/*.{js,ts,jsx,tsx,mdx}', + './app/**/*.{js,ts,jsx,tsx,mdx}', + ], + theme: { + extend: { + backgroundImage: { + 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', + 'gradient-conic': + 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', + }, + }, + }, + plugins: [], +}; diff --git a/packages/frontend/tsconfig.json b/packages/frontend/tsconfig.json new file mode 100644 index 0000000..9be0fa4 --- /dev/null +++ b/packages/frontend/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "paths": { + "*/*": ["./*"] + } + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], + "exclude": ["node_modules"] +}