From dc311af7782b3222c8522596aa64d9e0f7a3b581 Mon Sep 17 00:00:00 2001 From: reynandaptr-ro Date: Wed, 15 Jan 2025 21:01:21 +0700 Subject: [PATCH] feat: setup base --- api/package-lock.json | 302 ++++++++++++++++++++++++- api/package.json | 3 + api/script/default-server.ts | 4 +- api/script/models/account.ts | 38 ++++ api/script/storage/postgres.ts | 168 ++++++++++++++ api/script/storage/redis-s3-storage.ts | 6 +- 6 files changed, 515 insertions(+), 6 deletions(-) create mode 100644 api/script/models/account.ts create mode 100644 api/script/storage/postgres.ts diff --git a/api/package-lock.json b/api/package-lock.json index 09eec4fc5..b98b2d428 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -30,10 +30,13 @@ "passport-github2": "0.1.9", "passport-http-bearer": "1.0.1", "passport-windowslive": "1.0.1", + "pg": "^8.13.1", + "pg-hstore": "^2.3.4", "q": "^1.4.1", "redis": "2.4.2", "sanitize-html": "^2.11.0", "semver": "^7.5.3", + "sequelize": "^6.37.5", "shortid": "2.2.2", "stream-to-array": "^2.3.0", "streamifier": "0.1.1", @@ -2592,6 +2595,14 @@ "@types/node": "*" } }, + "node_modules/@types/debug": { + "version": "4.1.12", + "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", + "integrity": "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==", + "dependencies": { + "@types/ms": "*" + } + }, "node_modules/@types/express": { "version": "4.17.17", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.17.tgz", @@ -2668,6 +2679,11 @@ "integrity": "sha512-/fvYntiO1GeICvqbQ3doGDIP97vWmvFt83GKguJ6prmQM2iXZfFcq6YE8KteFyRtX2/h5Hf91BYvPodJKFYv5Q==", "dev": true }, + "node_modules/@types/ms": { + "version": "0.7.34", + "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", + "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" + }, "node_modules/@types/multer": { "version": "1.4.7", "resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.7.tgz", @@ -2777,6 +2793,11 @@ "@types/node": "*" } }, + "node_modules/@types/validator": { + "version": "13.12.2", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.12.2.tgz", + "integrity": "sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==" + }, "node_modules/@types/yargs": { "version": "17.0.24", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.24.tgz", @@ -3982,6 +4003,11 @@ "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, + "node_modules/dottie": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.6.tgz", + "integrity": "sha512-iGCHkfUc5kFekGiqhe8B/mdaurD+lakO9txNnTvKtA6PISrw86LgqHvRzWYPyoE2Ph5aMIrCw9/uko6XHTKCwA==" + }, "node_modules/double-ended-queue": { "version": "2.1.0-0", "resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz", @@ -5090,6 +5116,14 @@ "node": ">=0.8.19" } }, + "node_modules/inflection": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/inflection/-/inflection-1.13.4.tgz", + "integrity": "sha512-6I/HUDeYFfuNCVS3td055BaXBwKYuzw7K3ExVMStBowKo9oOAMJIXIHvdyR3iboTCp1b+1i5DSkIZTcwIktuDw==", + "engines": [ + "node >= 0.4.0" + ] + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -5732,7 +5766,17 @@ "version": "2.29.4", "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz", "integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==", - "optional": true, + "engines": { + "node": "*" + } + }, + "node_modules/moment-timezone": { + "version": "0.5.46", + "resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.46.tgz", + "integrity": "sha512-ZXm9b36esbe7OmdABqIWJuBBiLLwAjrN7CE+7sYdCCx82Nabt1wHDj8TVseS59QIlfFPbOoiBPm6ca9BioG4hw==", + "dependencies": { + "moment": "^2.29.4" + }, "engines": { "node": "*" } @@ -6254,6 +6298,98 @@ "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==" }, + "node_modules/pg": { + "version": "8.13.1", + "resolved": "https://registry.npmjs.org/pg/-/pg-8.13.1.tgz", + "integrity": "sha512-OUir1A0rPNZlX//c7ksiu7crsGZTKSOXJPgtNiHGIlC9H0lO+NC6ZDYksSgBYY/thSWhnSRBv8w1lieNNGATNQ==", + "dependencies": { + "pg-connection-string": "^2.7.0", + "pg-pool": "^3.7.0", + "pg-protocol": "^1.7.0", + "pg-types": "^2.1.0", + "pgpass": "1.x" + }, + "engines": { + "node": ">= 8.0.0" + }, + "optionalDependencies": { + "pg-cloudflare": "^1.1.1" + }, + "peerDependencies": { + "pg-native": ">=3.0.1" + }, + "peerDependenciesMeta": { + "pg-native": { + "optional": true + } + } + }, + "node_modules/pg-cloudflare": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.1.1.tgz", + "integrity": "sha512-xWPagP/4B6BgFO+EKz3JONXv3YDgvkbVrGw2mTo3D6tVDQRh1e7cqVGvyR3BE+eQgAvx1XhW/iEASj4/jCWl3Q==", + "optional": true + }, + "node_modules/pg-connection-string": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.7.0.tgz", + "integrity": "sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==" + }, + "node_modules/pg-hstore": { + "version": "2.3.4", + "resolved": "https://registry.npmjs.org/pg-hstore/-/pg-hstore-2.3.4.tgz", + "integrity": "sha512-N3SGs/Rf+xA1M2/n0JBiXFDVMzdekwLZLAO0g7mpDY9ouX+fDI7jS6kTq3JujmYbtNSJ53TJ0q4G98KVZSM4EA==", + "dependencies": { + "underscore": "^1.13.1" + }, + "engines": { + "node": ">= 0.8.x" + } + }, + "node_modules/pg-int8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", + "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/pg-pool": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.7.0.tgz", + "integrity": "sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==", + "peerDependencies": { + "pg": ">=8.0" + } + }, + "node_modules/pg-protocol": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.7.0.tgz", + "integrity": "sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==" + }, + "node_modules/pg-types": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", + "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", + "dependencies": { + "pg-int8": "1.0.1", + "postgres-array": "~2.0.0", + "postgres-bytea": "~1.0.0", + "postgres-date": "~1.0.4", + "postgres-interval": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pgpass": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", + "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", + "dependencies": { + "split2": "^4.1.0" + } + }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -6298,6 +6434,41 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/postgres-array": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", + "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", + "engines": { + "node": ">=4" + } + }, + "node_modules/postgres-bytea": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", + "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-date": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", + "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/postgres-interval": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", + "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", + "dependencies": { + "xtend": "^4.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -6583,6 +6754,11 @@ "node": ">=4" } }, + "node_modules/retry-as-promised": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/retry-as-promised/-/retry-as-promised-7.0.4.tgz", + "integrity": "sha512-XgmCoxKWkDofwH8WddD0w85ZfqYz+ZHlr5yo+3YUCfycWawU56T5ckWXsScsj5B8tqUcIG67DxXByo3VUgiAdA==" + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -6741,6 +6917,96 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" }, + "node_modules/sequelize": { + "version": "6.37.5", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-6.37.5.tgz", + "integrity": "sha512-10WA4poUb3XWnUROThqL2Apq9C2NhyV1xHPMZuybNMCucDsbbFuKg51jhmyvvAUyUqCiimwTZamc3AHhMoBr2Q==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/sequelize" + } + ], + "dependencies": { + "@types/debug": "^4.1.8", + "@types/validator": "^13.7.17", + "debug": "^4.3.4", + "dottie": "^2.0.6", + "inflection": "^1.13.4", + "lodash": "^4.17.21", + "moment": "^2.29.4", + "moment-timezone": "^0.5.43", + "pg-connection-string": "^2.6.1", + "retry-as-promised": "^7.0.4", + "semver": "^7.5.4", + "sequelize-pool": "^7.1.0", + "toposort-class": "^1.0.1", + "uuid": "^8.3.2", + "validator": "^13.9.0", + "wkx": "^0.5.0" + }, + "engines": { + "node": ">=10.0.0" + }, + "peerDependenciesMeta": { + "ibm_db": { + "optional": true + }, + "mariadb": { + "optional": true + }, + "mysql2": { + "optional": true + }, + "oracledb": { + "optional": true + }, + "pg": { + "optional": true + }, + "pg-hstore": { + "optional": true + }, + "snowflake-sdk": { + "optional": true + }, + "sqlite3": { + "optional": true + }, + "tedious": { + "optional": true + } + } + }, + "node_modules/sequelize-pool": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/sequelize-pool/-/sequelize-pool-7.1.0.tgz", + "integrity": "sha512-G9c0qlIWQSK29pR/5U2JF5dDQeqqHRragoyahj/Nx4KOOQ3CPPfzxnfqFPCSB7x5UgjOgnZ61nSxz+fjDpRlJg==", + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/sequelize/node_modules/debug": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/sequelize/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==" + }, "node_modules/serve-static": { "version": "1.16.2", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", @@ -6906,6 +7172,14 @@ "node": ">=0.10.0" } }, + "node_modules/split2": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", + "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", + "engines": { + "node": ">= 10.x" + } + }, "node_modules/stack-chain": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/stack-chain/-/stack-chain-1.3.7.tgz", @@ -7219,6 +7493,11 @@ "node": ">=0.6" } }, + "node_modules/toposort-class": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toposort-class/-/toposort-class-1.0.1.tgz", + "integrity": "sha512-OsLcGGbYF3rMjPUf8oKktyvCiUxSbqMMS39m33MAjLTC1DVIH6x3WSt63/M77ihI09+Sdfk1AXvfhCEeUmC7mg==" + }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", @@ -7325,6 +7604,11 @@ "resolved": "https://registry.npmjs.org/uid2/-/uid2-0.0.4.tgz", "integrity": "sha512-IevTus0SbGwQzYh3+fRsAMTVVPOoIVufzacXcHPmdlle1jUpq7BRL+mw3dgeLanvGZdwwbWhRV6XrcFNdBmjWA==" }, + "node_modules/underscore": { + "version": "1.13.7", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", + "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==" + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -7368,6 +7652,14 @@ "resolved": "https://registry.npmjs.org/valid-url/-/valid-url-1.0.9.tgz", "integrity": "sha512-QQDsV8OnSf5Uc30CKSwG9lnhMPe6exHtTXLRYX8uMwKENy640pU+2BgBL0LRbDh/eYRahNCS7aewCx0wf3NYVA==" }, + "node_modules/validator": { + "version": "13.12.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz", + "integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==", + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", @@ -7405,6 +7697,14 @@ "node": ">= 8" } }, + "node_modules/wkx": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/wkx/-/wkx-0.5.0.tgz", + "integrity": "sha512-Xng/d4Ichh8uN4l0FToV/258EjMGU9MGcA0HV2d9B/ZpZB3lqQm7nkOdZdm5GhKtLLhAE7PiVQwN4eN+2YJJUg==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/wrap-ansi": { "version": "8.1.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", diff --git a/api/package.json b/api/package.json index f8807f5d7..4e1cd2866 100644 --- a/api/package.json +++ b/api/package.json @@ -44,10 +44,13 @@ "passport-github2": "0.1.9", "passport-http-bearer": "1.0.1", "passport-windowslive": "1.0.1", + "pg": "^8.13.1", + "pg-hstore": "^2.3.4", "q": "^1.4.1", "redis": "2.4.2", "sanitize-html": "^2.11.0", "semver": "^7.5.3", + "sequelize": "^6.37.5", "shortid": "2.2.2", "stream-to-array": "^2.3.0", "streamifier": "0.1.1", diff --git a/api/script/default-server.ts b/api/script/default-server.ts index 97fed463a..724dbe44e 100644 --- a/api/script/default-server.ts +++ b/api/script/default-server.ts @@ -11,7 +11,7 @@ import * as bodyParser from "body-parser"; const domain = require("express-domain-middleware"); import * as express from "express"; import * as q from "q"; -import { RedisS3Storage } from "./storage/redis-s3-storage"; +import { PostgresStorage } from "./storage/postgres"; interface Secret { id: string; @@ -36,7 +36,7 @@ export function start(done: (err?: any, server?: express.Express, storage?: Stor q(null) .then(async () => { - storage = new RedisS3Storage(); + storage = new PostgresStorage(); }) .then(() => { const app = express(); diff --git a/api/script/models/account.ts b/api/script/models/account.ts new file mode 100644 index 000000000..5524a8d56 --- /dev/null +++ b/api/script/models/account.ts @@ -0,0 +1,38 @@ +import {Sequelize, DataTypes, Model, Optional} from 'sequelize'; + +type AccountAttributes = { + id: string + email: string + gitHubId: string +} + +type AccountCreationAttributes = Optional; + +export class Account extends Model { + declare id: number; + declare email: string; + declare githubId: string; +} + +export const initAccountModel = (sequelize: Sequelize) => { + Account.init({ + id: { + type: DataTypes.INTEGER, + primaryKey: true, + autoIncrement: true, + }, + email: { + type: DataTypes.STRING, + allowNull: false, + unique: true, + }, + gitHubId: { + type: DataTypes.STRING, + allowNull: false, + unique: true, + }, + }, { + modelName: 'Account', + sequelize, + }); +} diff --git a/api/script/storage/postgres.ts b/api/script/storage/postgres.ts new file mode 100644 index 000000000..8734bf41c --- /dev/null +++ b/api/script/storage/postgres.ts @@ -0,0 +1,168 @@ +import {Sequelize} from 'sequelize'; +import * as stream from "stream"; +import * as q from "q"; + +import Promise = q.Promise; + +import * as storage from "./storage"; +import { Account, initAccountModel } from '../models/account'; + + +export class PostgresStorage { + private sequelize: Sequelize; + + constructor() { + this.sequelize = new Sequelize('database', 'username', 'password', { + host: 'localhost', + port: 5432, + dialect: 'postgres', + }); + + this.connect(); + this.initModels(); + } + + private connect() { + return this.sequelize.authenticate(); + } + + private initModels() { + initAccountModel(this.sequelize); + } + + public checkHealth(): Promise { + return q(null); + } + + public async addAccount(account: storage.Account): globalThis.Promise { + const newAccount = new Account({ + email: account.email.toLowerCase(), + gitHubId: account.gitHubId, + }) + try { + const existingAccount = await Account.findOne({ + where: { + email: newAccount.email, + }, + }) + if (!!existingAccount) { + return PostgresStorage.getRejectedPromise(storage.ErrorCode.AlreadyExists) + } + await newAccount.save() + return q(`${newAccount.id}`) + } catch (error) { + return PostgresStorage.getRejectedPromise(storage.ErrorCode.ConnectionFailed) + } + } + + public getAccount(accountId: string): Promise { + return q.resolve(null) + } + public getAccountByEmail(email: string): Promise { + return q.resolve(null) + } + public getAccountIdFromAccessKey(accessKey: string): Promise { + return q.resolve('') + } + public updateAccount(email: string, updates: storage.Account): Promise { + return q.resolve() + } + + public addApp(accountId: string, app: storage.App): Promise { + return q.resolve(null) + } + public getApps(accountId: string): Promise { + return q.resolve([]) + } + public getApp(accountId: string, appId: string): Promise { + return q.resolve(null) + } + public removeApp(accountId: string, appId: string): Promise { + return q.resolve() + } + public transferApp(accountId: string, appId: string, email: string): Promise { + return q.resolve() + } + public updateApp(accountId: string, app: storage.App): Promise { + return q.resolve() + } + + public addCollaborator(accountId: string, appId: string, email: string): Promise { + return q.resolve() + } + public getCollaborators(accountId: string, appId: string): Promise { + return q.resolve(null) + } + public removeCollaborator(accountId: string, appId: string, email: string): Promise { + return q.resolve() + } + + public addDeployment(accountId: string, appId: string, deployment: storage.Deployment): Promise { + return q.resolve('') + } + public getDeployment(accountId: string, appId: string, deploymentId: string): Promise { + return q.resolve(null) + } + public getDeploymentInfo(deploymentKey: string): Promise { + return q.resolve(null) + } + public getDeployments(accountId: string, appId: string): Promise { + return q.resolve([]) + } + public removeDeployment(accountId: string, appId: string, deploymentId: string): Promise { + return q.resolve() + } + public updateDeployment(accountId: string, appId: string, deployment: storage.Deployment): Promise { + return q.resolve() + } + + public commitPackage(accountId: string, appId: string, deploymentId: string, appPackage: storage.Package): Promise { + return q.resolve(null) + } + public clearPackageHistory(accountId: string, appId: string, deploymentId: string): Promise { + return q.resolve() + } + public getPackageHistoryFromDeploymentKey(deploymentKey: string): Promise { + return q.resolve([]) + } + public getPackageHistory(accountId: string, appId: string, deploymentId: string): Promise { + return q.resolve(null) + } + public updatePackageHistory(accountId: string, appId: string, deploymentId: string, history: storage.Package[]): Promise { + return q.resolve() + } + + public addBlob(blobId: string, addstream: stream.Readable, streamLength: number): Promise { + return q.resolve('') + } + public getBlobUrl(blobId: string): Promise { + return q.resolve('') + } + public removeBlob(blobId: string): Promise { + return q.resolve() + } + + public addAccessKey(accountId: string, accessKey: storage.AccessKey): Promise { + return q.resolve('') + } + public getAccessKey(accountId: string, accessKeyId: string): Promise { + return q.resolve(null) + } + public getAccessKeys(accountId: string): Promise { + return q.resolve([]) + } + public removeAccessKey(accountId: string, accessKeyId: string): Promise { + return q.resolve() + } + public updateAccessKey(accountId: string, accessKey: storage.AccessKey): Promise { + return q.resolve() + } + + public dropAll(): Promise { + return q.resolve(); + } + + private static getRejectedPromise(errorCode: storage.ErrorCode, message?: string): Promise { + return q.reject(storage.storageError(errorCode, message)); + } +} \ No newline at end of file diff --git a/api/script/storage/redis-s3-storage.ts b/api/script/storage/redis-s3-storage.ts index 2708c88e5..5b8a3cce5 100644 --- a/api/script/storage/redis-s3-storage.ts +++ b/api/script/storage/redis-s3-storage.ts @@ -278,7 +278,7 @@ export class RedisS3Storage implements storage.Storage { }); } - public updateApp(accountId: string, app: storage.App, ensureIsOwner: boolean = true): Promise { + public updateApp(accountId: string, app: storage.App): Promise { app = clone(app); // pass by value if (!this.accounts[accountId] || !this.apps[app.id]) { @@ -365,7 +365,7 @@ export class RedisS3Storage implements storage.Storage { this.removeAppPointer(targetCollaboratorAccountId, appId); delete app.collaborators[email]; - return this.updateApp(accountId, app, /*ensureIsOwner*/ false); + return this.updateApp(accountId, app); }); } @@ -768,7 +768,7 @@ export class RedisS3Storage implements storage.Storage { if (!this._blobServerPromise) { const app: express.Express = express(); - app.get("/:blobId", (req: express.Request, res: express.Response, next: (err?: Error) => void): any => { + app.get("/:blobId", (req: express.Request, res: express.Response): any => { const blobId: string = req.params.blobId; if (this.blobs[blobId]) { res.send(this.blobs[blobId]);