Compare commits

...

13 Commits

Author SHA1 Message Date
Kayne Ruse 78cda0fe50 Enabled HTML embedding 2022-01-06 11:31:11 +00:00
Kayne Ruse 7d40005e7d Bumped version number 2022-01-02 18:12:31 +00:00
Kayne Ruse 855de182ea Mods can now add and edit the news feed 2022-01-02 18:11:43 +00:00
Kayne Ruse a96e7d9344 Updated README.md 2021-12-30 13:52:13 +00:00
Kayne Ruse 2e2799f2d3 Moved client-side markdown rendering to this server 2021-12-30 13:22:31 +00:00
Kayne Ruse da0c4bbd05 Cleaned up tools and tests 2021-12-23 13:57:52 +00:00
Kayne Ruse 6e75012376 Updated README.md 2021-12-21 19:37:38 +00:00
Kayne Ruse 5488d7a8d7 Preparing for Egg Trainer merge 2021-11-18 14:58:29 +00:00
Kayne Ruse 3bb0b2aa29 Fixed revisions table losing originalIndex when article was deleted
I've also included a migration file in the tools directory
2021-11-17 06:16:33 +00:00
Kayne Ruse c30cf80fc6 Bumped node to version 16 LTS 2021-11-17 04:42:48 +00:00
Kayne Ruse 62afef402f Updated package-lock.json 2021-11-15 22:39:21 +00:00
Kayne Ruse db61357a0f Updated documentation 2021-08-21 22:45:01 +01:00
Kayne Ruse fd1ba06b45 HOTFIX: Missing data would crash the site 2021-07-25 10:35:13 +01:00
20 changed files with 332 additions and 204 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
docker_image: krgamestudios/news-server docker_image: krgamestudios/news-server
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with:
username: ${{ secrets.DOCKER_USERNAME }} username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }} password: ${{ secrets.DOCKER_PASSWORD }}
+2 -2
View File
@@ -1,9 +1,9 @@
FROM node:15 FROM node:16
WORKDIR "/app" WORKDIR "/app"
COPY package*.json ./ COPY package*.json ./
COPY . /app
RUN npm install --production RUN npm install --production
COPY . /app
EXPOSE 3100 EXPOSE 3100
USER node USER node
ENTRYPOINT ["bash", "-c"] ENTRYPOINT ["bash", "-c"]
+48 -16
View File
@@ -2,14 +2,16 @@
An API centric news server. Uses Sequelize and mariaDB by default. An API centric news server. Uses Sequelize and mariaDB by default.
This server is available via docker hub at krgamestudios/news-server.
# Setup # Setup
There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql. There are multiple ways to run this app - it can run on it's own via `npm start` (for production) or `npm run dev` (for development). it can also run inside docker using `docker-compose up --build` - run `node configure-script.js` to generate docker-compose.yml and startup.sql.
To generate an authorization token, use [auth-server](https://github.com/krgamestudios/auth-server). A public-facing development auth-server is available here (tokens are 10 minutes): To generate an authorization token, use [auth-server](https://github.com/krgamestudios/auth-server). A public-facing development auth-server is available here (tokens are valid for 10 minutes):
``` ```
POST https://dev-auth.eggtrainer.com/auth/login HTTP/1.1 POST https://dev-auth.krgamestudios.com/auth/login HTTP/1.1
Content-Type: application/json Content-Type: application/json
{ {
@@ -25,19 +27,28 @@ Content-Type: application/json
//NOTE: you can add a "limit" query parameter to change the default limit //NOTE: you can add a "limit" query parameter to change the default limit
GET /news?limit=10 GET /news?limit=10
//get latest news, up to a default limit, or specify the index "id"
###
//DOCS: get latest news, up to a default limit, or specify the index "id"
GET /news/:id GET /news/:id
//get the news starting from the beginning, up to a default limit, or specify the index "id"
###
//DOCS: get the news starting from the beginning, up to a default limit, or specify the index "id"
GET /news/archive/:id GET /news/archive/:id
//result (if only a single article is specified, returns just that article rather than an array): //DOCS: result (if only a single article is specified, returns just that article rather than an array):
[ [
{ {
"index": index, //absolute index of the result "index": index, //absolute index of the result
"title": title, //title of the article "title": title, //title of the article
"author": author, //author of the aricle "author": author, //author of the aricle
"body": body, //body of the article "body": body, //body of the article
"rendered": rendered //body rendered as HTML
"edits": edits //number of times this article has been edited "edits": edits //number of times this article has been edited
"createdAt": createdAt //time created "createdAt": createdAt //time created
"updatedAt": updatedAt //time updated "updatedAt": updatedAt //time updated
@@ -45,13 +56,21 @@ GET /news/archive/:id
... ...
] ]
//get the latest metadata, up to a default limit, or specify the index "id"
###
//DOCS: get the latest metadata, up to a default limit, or specify the index "id"
GET /news/metadata/:id GET /news/metadata/:id
//get the metadata starting from the beginning, up to a default limit, or specify the index "id"
###
//DOCS: get the metadata starting from the beginning, up to a default limit, or specify the index "id"
GET /news/archive/metadata/:id GET /news/archive/metadata/:id
//result (if only a single article is specified, returns just that article rather than an array): //DOCS: result (if only a single article is specified, returns just that article rather than an array):
[ [
{ {
"index": index, //absolute index of the result "index": index, //absolute index of the result
@@ -64,38 +83,51 @@ GET /news/archive/metadata/:id
... ...
] ]
//send a formatted JSON object, returns new index on success, or error on failure
###
//DOCS: send a formatted JSON object, returns new index on success, or error on failure
POST /news POST /news
Authorization: Bearer XXX Authorization: Bearer XXX
//arguments:
{ {
"title": title //title of the article "title": title //title of the article
"author": author //author of the article "author": author //author of the article
"body": body //body of the article "body": body //body of the article
} }
//result (status 200 on success, otherwise an error status): //DOCS: result (status 200 on success, otherwise an error status):
{ {
"index": index //new index of the article "index": index //new index of the article
} }
//similar to `POST /news`, but allows overwriting an existing article
###
//DOCS: similar to `POST /news`, but allows overwriting an existing article
PATCH /news/:id PATCH /news/:id
Authorization: Bearer XXX Authorization: Bearer XXX
//arguments:
{ {
"title": title //title of the article, optional "title": title //title of the article, optional
"author": author //author of the article, optional "author": author //author of the article, optional
"body": body //body of the article, optional "body": body //body of the article, optional
} }
result: status 200 on success, otherwise an error status //DOCS: result: status 200 on success, otherwise an error status
//remove an article from the news feed
###
//DOCS: remove an article from the news feed
DELETE /news/:id DELETE /news/:id
Authorization: Bearer XXX Authorization: Bearer XXX
//result: status 200 on success, otherwise an error status //DOCS: result: status 200 on success, otherwise an error status
###
``` ```
+2 -2
View File
@@ -33,7 +33,7 @@ const question = (prompt, def = null) => {
const appPort = await question('App Port', '3100'); const appPort = await question('App Port', '3100');
const appDBUser = await question('DB User', appName); const appDBUser = await question('DB User', appName);
const appDBPass = await question('DB Pass', uuid()); const appDBPass = await question('DB Pass', 'venusaur');
const dbRootPass = await question('DB Root Pass'); const dbRootPass = await question('DB Root Pass');
const appSecretAccess = await question('Access Token Secret', uuid(32)); const appSecretAccess = await question('Access Token Secret', uuid(32));
@@ -109,7 +109,7 @@ networks:
`; `;
const dockerfile = ` const dockerfile = `
FROM node:15 FROM node:16
WORKDIR "/app" WORKDIR "/app"
COPY package*.json ./ COPY package*.json ./
RUN npm install --production RUN npm install --production
+110 -112
View File
@@ -1,11 +1,12 @@
{ {
"name": "news-server", "name": "news-server",
"version": "1.1.1", "version": "1.4.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"version": "1.1.1", "name": "news-server",
"version": "1.4.2",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"cors": "^2.8.5", "cors": "^2.8.5",
@@ -13,6 +14,7 @@
"express": "^4.17.1", "express": "^4.17.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mariadb": "^2.5.4", "mariadb": "^2.5.4",
"markdown-it": "^12.3.0",
"sequelize": "^6.6.5" "sequelize": "^6.6.5"
}, },
"devDependencies": { "devDependencies": {
@@ -69,68 +71,18 @@
} }
}, },
"node_modules/ansi-align": { "node_modules/ansi-align": {
"version": "3.0.0", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz",
"integrity": "sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw==", "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"string-width": "^3.0.0" "string-width": "^4.1.0"
}
},
"node_modules/ansi-align/node_modules/ansi-regex": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
"dev": true,
"engines": {
"node": ">=6"
}
},
"node_modules/ansi-align/node_modules/emoji-regex": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz",
"integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==",
"dev": true
},
"node_modules/ansi-align/node_modules/is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true,
"engines": {
"node": ">=4"
}
},
"node_modules/ansi-align/node_modules/string-width": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz",
"integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==",
"dev": true,
"dependencies": {
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
},
"engines": {
"node": ">=6"
}
},
"node_modules/ansi-align/node_modules/strip-ansi": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
"integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
"dev": true,
"dependencies": {
"ansi-regex": "^4.1.0"
},
"engines": {
"node": ">=6"
} }
}, },
"node_modules/ansi-regex": { "node_modules/ansi-regex": {
"version": "5.0.0", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true, "dev": true,
"engines": { "engines": {
"node": ">=8" "node": ">=8"
@@ -169,6 +121,11 @@
"node": ">= 8" "node": ">= 8"
} }
}, },
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"node_modules/array-flatten": { "node_modules/array-flatten": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@@ -616,6 +573,14 @@
"once": "^1.4.0" "once": "^1.4.0"
} }
}, },
"node_modules/entities": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz",
"integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==",
"funding": {
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/escape-goat": { "node_modules/escape-goat": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz",
@@ -1081,6 +1046,14 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/linkify-it": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz",
"integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==",
"dependencies": {
"uc.micro": "^1.0.1"
}
},
"node_modules/lodash": { "node_modules/lodash": {
"version": "4.17.21", "version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
@@ -1198,6 +1171,26 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/markdown-it": {
"version": "12.3.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.0.tgz",
"integrity": "sha512-T345UZZ6ejQWTjG6PSEHplzNy5m4kF6zvUpHVDv8Snl/pEU0OxIK0jGg8YLVNwJvT8E0YJC7/2UvssJDk/wQCQ==",
"dependencies": {
"argparse": "^2.0.1",
"entities": "~2.1.0",
"linkify-it": "^3.0.1",
"mdurl": "^1.0.1",
"uc.micro": "^1.0.5"
},
"bin": {
"markdown-it": "bin/markdown-it.js"
}
},
"node_modules/mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
"integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4="
},
"node_modules/media-typer": { "node_modules/media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@@ -1952,6 +1945,11 @@
"is-typedarray": "^1.0.0" "is-typedarray": "^1.0.0"
} }
}, },
"node_modules/uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
"integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
},
"node_modules/undefsafe": { "node_modules/undefsafe": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz",
@@ -2037,9 +2035,9 @@
} }
}, },
"node_modules/validator": { "node_modules/validator": {
"version": "13.6.0", "version": "13.7.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.6.0.tgz", "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
"integrity": "sha512-gVgKbdbHgtxpRyR8K0O6oFZPhhB5tT1jeEHZR0Znr9Svg03U0+r9DXWMrnRAB+HtCStDQKlaIZm42tVsVjqtjg==", "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw==",
"engines": { "engines": {
"node": ">= 0.10" "node": ">= 0.10"
} }
@@ -2147,58 +2145,18 @@
} }
}, },
"ansi-align": { "ansi-align": {
"version": "3.0.0", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz",
"integrity": "sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw==", "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==",
"dev": true, "dev": true,
"requires": { "requires": {
"string-width": "^3.0.0" "string-width": "^4.1.0"
},
"dependencies": {
"ansi-regex": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==",
"dev": true
},
"emoji-regex": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz",
"integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==",
"dev": true
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"dev": true
},
"string-width": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz",
"integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==",
"dev": true,
"requires": {
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
}
},
"strip-ansi": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
"integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
"dev": true,
"requires": {
"ansi-regex": "^4.1.0"
}
}
} }
}, },
"ansi-regex": { "ansi-regex": {
"version": "5.0.0", "version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true "dev": true
}, },
"ansi-styles": { "ansi-styles": {
@@ -2225,6 +2183,11 @@
"picomatch": "^2.0.4" "picomatch": "^2.0.4"
} }
}, },
"argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
"integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="
},
"array-flatten": { "array-flatten": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
@@ -2581,6 +2544,11 @@
"once": "^1.4.0" "once": "^1.4.0"
} }
}, },
"entities": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz",
"integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w=="
},
"escape-goat": { "escape-goat": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz", "resolved": "https://registry.npmjs.org/escape-goat/-/escape-goat-2.1.1.tgz",
@@ -2948,6 +2916,14 @@
"package-json": "^6.3.0" "package-json": "^6.3.0"
} }
}, },
"linkify-it": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz",
"integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==",
"requires": {
"uc.micro": "^1.0.1"
}
},
"lodash": { "lodash": {
"version": "4.17.21", "version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
@@ -3048,6 +3024,23 @@
} }
} }
}, },
"markdown-it": {
"version": "12.3.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.0.tgz",
"integrity": "sha512-T345UZZ6ejQWTjG6PSEHplzNy5m4kF6zvUpHVDv8Snl/pEU0OxIK0jGg8YLVNwJvT8E0YJC7/2UvssJDk/wQCQ==",
"requires": {
"argparse": "^2.0.1",
"entities": "~2.1.0",
"linkify-it": "^3.0.1",
"mdurl": "^1.0.1",
"uc.micro": "^1.0.5"
}
},
"mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
"integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4="
},
"media-typer": { "media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
@@ -3608,6 +3601,11 @@
"is-typedarray": "^1.0.0" "is-typedarray": "^1.0.0"
} }
}, },
"uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
"integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
},
"undefsafe": { "undefsafe": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.3.tgz",
@@ -3672,9 +3670,9 @@
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==" "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
}, },
"validator": { "validator": {
"version": "13.6.0", "version": "13.7.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.6.0.tgz", "resolved": "https://registry.npmjs.org/validator/-/validator-13.7.0.tgz",
"integrity": "sha512-gVgKbdbHgtxpRyR8K0O6oFZPhhB5tT1jeEHZR0Znr9Svg03U0+r9DXWMrnRAB+HtCStDQKlaIZm42tVsVjqtjg==" "integrity": "sha512-nYXQLCBkpJ8X6ltALua9dRrZDHVYxjJ1wgskNt1lH9fzGjs3tgojGSCBjmEPwkWS1y29+DrizMTW19Pr9uB2nw=="
}, },
"vary": { "vary": {
"version": "1.1.2", "version": "1.1.2",
+2 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "news-server", "name": "news-server",
"version": "1.2.1", "version": "1.4.2",
"description": "An API centric news server. Uses Sequelize and mariaDB by default.", "description": "An API centric news server. Uses Sequelize and mariaDB by default.",
"main": "server/server.js", "main": "server/server.js",
"scripts": { "scripts": {
@@ -24,6 +24,7 @@
"express": "^4.17.1", "express": "^4.17.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"mariadb": "^2.5.4", "mariadb": "^2.5.4",
"markdown-it": "^12.3.0",
"sequelize": "^6.6.5" "sequelize": "^6.6.5"
}, },
"devDependencies": { "devDependencies": {
+5
View File
@@ -25,6 +25,11 @@ const articles = sequelize.define('articles', {
defaultValue: '' defaultValue: ''
}, },
rendered: {
type: Sequelize.TEXT,
defaultValue: ''
},
edits: { edits: {
type: Sequelize.INTEGER(11), type: Sequelize.INTEGER(11),
defaultValue: 0 defaultValue: 0
+18 -4
View File
@@ -1,9 +1,15 @@
const Sequelize = require('sequelize'); const Sequelize = require('sequelize');
const sequelize = require('..'); const sequelize = require('..');
const articles = require('./articles');
const revisions = sequelize.define('revisions', { const revisions = sequelize.define('revisions', {
index: {
type: Sequelize.INTEGER(11),
allowNull: false,
autoIncrement: true,
primaryKey: true,
unique: true
},
title: { title: {
type: Sequelize.TEXT, type: Sequelize.TEXT,
defaultValue: '' defaultValue: ''
@@ -17,12 +23,20 @@ const revisions = sequelize.define('revisions', {
body: { body: {
type: Sequelize.TEXT, type: Sequelize.TEXT,
defaultValue: '' defaultValue: ''
},
rendered: {
type: Sequelize.TEXT,
defaultValue: ''
},
originalIndex: {
type: Sequelize.INTEGER(11),
default: null
} }
}); });
//relationships //relationships
articles.hasOne(revisions, { as: 'original' });
sequelize.sync(); sequelize.sync();
module.exports = revisions; module.exports = revisions;
+6 -3
View File
@@ -1,5 +1,6 @@
const { Op } = require('sequelize'); const { Op } = require('sequelize');
const { articles, revisions } = require('../database/models'); const { articles, revisions } = require('../database/models');
const markdownIt = require('markdown-it')({ html: true });
const route = async (req, res) => { const route = async (req, res) => {
//get the existing record //get the existing record
@@ -20,14 +21,16 @@ const route = async (req, res) => {
title: record.title, title: record.title,
author: record.author, author: record.author,
body: record.body, body: record.body,
rendered: record.rendered,
originalIndex: record.index originalIndex: record.index
}); });
//update the data //update the data
await articles.update({ await articles.update({
title: req.body.title, title: req.body.title || record.title,
author: req.body.author, author: req.body.author || record.author,
body: req.body.body, body: req.body.body || record.body,
rendered: markdownIt.render(req.body.body) || record.rendered,
edits: record.edits + 1 edits: record.edits + 1
}, { }, {
where: { where: {
+1 -1
View File
@@ -23,7 +23,7 @@ router.get('/archive/metadata/:id(\\d+)', query(true, true));
//use middleware to authenticate the rest of the routes //use middleware to authenticate the rest of the routes
router.use(authToken); router.use(authToken);
router.use((req, res, next) => { router.use((req, res, next) => {
if (req.user.admin) { if (req.user.mod) {
next(); next();
} else { } else {
res.status(403).end(); res.status(403).end();
+16 -1
View File
@@ -1,11 +1,26 @@
const { articles } = require('../database/models'); const { articles } = require('../database/models');
const markdownIt = require('markdown-it')({ html: true });
const route = async (req, res) => { const route = async (req, res) => {
//check for missing data
if (!req.body.title) {
return res.status(401).end("Missing title");
}
if (!req.body.author) {
return res.status(401).end("Missing author");
}
if (!req.body.body) {
return res.status(401).end("Missing body");
}
//upsert the data //upsert the data
const [instance, created] = await articles.upsert({ const [instance, created] = await articles.upsert({
title: req.body.title, title: req.body.title,
author: req.body.author, author: req.body.author,
body: req.body.body body: req.body.body,
rendered: markdownIt.render(req.body.body),
}); });
if (!created) { if (!created) {
+2 -2
View File
@@ -7,7 +7,7 @@ const query = (ascending, metadataOnly) => async (req, res) => {
if (req.params.id && typeof(parseInt(req.params.id)) === 'number') { if (req.params.id && typeof(parseInt(req.params.id)) === 'number') {
const result = await articles.findOne({ const result = await articles.findOne({
attributes: [ attributes: [
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body'] : []) 'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body', 'rendered'] : [])
], ],
where: { where: {
index: { index: {
@@ -24,7 +24,7 @@ const query = (ascending, metadataOnly) => async (req, res) => {
else { else {
const result = await articles.findAndCountAll({ const result = await articles.findAndCountAll({
attributes: [ attributes: [
'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body'] : []) 'index', 'title', 'author', 'edits', 'createdAt', 'updatedAt', ...(!metadataOnly ? ['body', 'rendered'] : [])
], ],
order: [ order: [
['index', ascending ? 'ASC' : 'DESC'] ['index', ascending ? 'ASC' : 'DESC']
+1
View File
@@ -20,6 +20,7 @@ const route = async (req, res) => {
title: record.title, title: record.title,
author: record.author, author: record.author,
body: record.body, body: record.body,
rendered: record.rendered,
originalIndex: record.index originalIndex: record.index
}); });
+44
View File
@@ -26,4 +26,48 @@ app.get('*', (req, res) => {
server.listen(process.env.WEB_PORT || 3100, async (err) => { server.listen(process.env.WEB_PORT || 3100, async (err) => {
await database.sync(); await database.sync();
console.log(`listening to localhost:${process.env.WEB_PORT || 3100}`); console.log(`listening to localhost:${process.env.WEB_PORT || 3100}`);
//parse the unrendered data from the database
const markdownIt = require('markdown-it')();
const { articles, revisions } = require('./database/models');
const missingArticles = await articles.findAll({
where: {
rendered: ''
}
});
const missingRevisions = await revisions.findAll({
where: {
rendered: ''
}
});
await Promise.all(
missingArticles.map(async ma => {
ma.update({
rendered: markdownIt.render(ma.body)
}, {
where: {
index: ma.index
}
});
})
)
.then(result => {if (result.length > 0) console.log('Rendered articles in HTML'); })
;
await Promise.all(
missingRevisions.map(async mr => {
mr.update({
rendered: markdownIt.render(mr.body)
}, {
where: {
index: mr.index
}
});
})
)
.then(result => {if (result.length > 0) console.log('Rendered revisions in HTML'); })
;
}); });
+16 -5
View File
@@ -1,23 +1,34 @@
#Query #Query
GET https://dev-news.eggtrainer.com/news HTTP/1.1 GET https://dev-news.krgamestudios.com/news HTTP/1.1
###
#Login
POST https://dev-auth.krgamestudios.com/auth/login HTTP/1.1
Content-Type: application/json
{
"email": "example@example.com",
"password": "helloworld"
}
### ###
#Publish #Publish
POST https://dev-news.eggtrainer.com/news HTTP/1.1 POST https://dev-news.krgamestudios.com/news HTTP/1.1
Content-Type: application/json Content-Type: application/json
Authorization: Bearer Authorization: Bearer
{ {
"title": "Hello World", "title": "Hello World",
"author": "Kayne Ruse", "author": "Anonymous",
"body": "Lorem ipsum." "body": "Lorem ipsum."
} }
### ###
#Edit #Edit
PATCH https://dev-news.eggtrainer.com/news/1 HTTP/1.1 PATCH https://dev-news.krgamestudios.com/news/1 HTTP/1.1
Content-Type: application/json Content-Type: application/json
Authorization: Bearer Authorization: Bearer
@@ -28,6 +39,6 @@ Authorization: Bearer
### ###
#Delete #Delete
DELETE https://dev-news.eggtrainer.com/news/1 HTTP/1.1 DELETE https://dev-news.krgamestudios.com/news/1 HTTP/1.1
Content-Type: application/json Content-Type: application/json
Authorization: Bearer Authorization: Bearer
+44
View File
@@ -0,0 +1,44 @@
#Query
GET http://localhost:3100/news HTTP/1.1
###
#Login
POST https://dev-auth.krgamestudios.com/auth/login HTTP/1.1
Content-Type: application/json
{
"email": "example@example.com",
"password": "helloworld"
}
###
#Publish
POST http://localhost:3100/news HTTP/1.1
Content-Type: application/json
Authorization: Bearer
{
"title": "Hello World",
"author": "Anonymous",
"body": "Lorem ipsum."
}
###
#Edit
PATCH http://localhost:3100/news/1 HTTP/1.1
Content-Type: application/json
Authorization: Bearer
{
"title": "Goodnight World"
}
###
#Delete
DELETE http://localhost:3100/news/1 HTTP/1.1
Content-Type: application/json
Authorization: Bearer
-54
View File
@@ -1,54 +0,0 @@
#Login to the auth-server
POST http://127.0.0.1:3200/auth/login HTTP/1.1
Content-Type: application/json
{
"email": "kayneruse@gmail.com",
"password": "helloworld"
}
###
#Refresh from the auth-server
POST http://127.0.0.1:3200/auth/token HTTP/1.1
Content-Type: application/json
{
"token": ""
}
###
#Query
GET http://127.0.0.1:3100/news HTTP/1.1
###
#Publish
POST http://127.0.0.1:3100/news HTTP/1.1
Content-Type: application/json
Authorization: Bearer
{
"title": "Hello World",
"author": "Kayne Ruse",
"body": "Lorem ipsum dolor sit amet..."
}
###
#Edit
PATCH http://127.0.0.1:3100/news/5 HTTP/1.1
Content-Type: application/json
Authorization: Bearer
{
"title": "Goodnight World"
}
###
#Delete
DELETE http://127.0.0.1:3100/news/4 HTTP/1.1
Content-Type: application/json
Authorization: Bearer
+4
View File
@@ -0,0 +1,4 @@
#use this while debugging
CREATE DATABASE IF NOT EXISTS news;
CREATE USER IF NOT EXISTS 'news'@'%' IDENTIFIED BY 'venusaur';
GRANT ALL PRIVILEGES ON news.* TO 'news'@'%';
+6
View File
@@ -0,0 +1,6 @@
use news;
ALTER TABLE revisions CHANGE COLUMN id `index` INTEGER(11) UNIQUE NOT NULL AUTO_INCREMENT;
ALTER TABLE revisions DROP FOREIGN KEY revisions_ibfk_1;
ALTER TABLE revisions CHANGE COLUMN originalIndex originalIndex INTEGER(11);
+4
View File
@@ -0,0 +1,4 @@
ALTER TABLE articles ADD COLUMN rendered TEXT DEFAULT "" AFTER body;
ALTER TABLE revisions ADD COLUMN rendered TEXT DEFAULT "" AFTER body;