docker: add dockerfile, format log

This commit is contained in:
bee! 2023-10-22 16:31:10 -07:00
parent 1564a110e0
commit 5e0fe8aa0c
No known key found for this signature in database
GPG key ID: A350C9117C864EB7
3 changed files with 41 additions and 13 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
node_modules
npm-debug.log

16
Dockerfile Normal file
View file

@ -0,0 +1,16 @@
FROM node:18
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --omit=dev
# Bundle app source
COPY . .
#EXPOSE 8080
CMD [ "node", "index.js" ]

View file

@ -52,7 +52,7 @@ async function findPrimary() {
if (fronter.content.customStatus) { if (fronter.content.customStatus) {
if (fronter.content.customStatus.toLowerCase().includes("primary")) { if (fronter.content.customStatus.toLowerCase().includes("primary")) {
let member = await system.getMemberById(fronter.content.member) let member = await system.getMemberById(fronter.content.member)
resolve(member.content.pkId) resolve({ name: member.content.name, pkId: member.content.pkId })
found = true found = true
} }
} }
@ -112,21 +112,30 @@ async function swapFront() {
// start forming new front list // start forming new front list
let newFront = [] let newFront = []
let frontNames = []
for (member of front) { for (member of front) {
let m = await system.getMemberById(member.content.member) let m = await system.getMemberById(member.content.member)
if (m.content.pkId) { if (m.content.pkId) {
// fronting member pkID has been found // fronting member pkID has been found
newFront.push(m.content.pkId) newFront.push(m.content.pkId)
frontNames.push(m.content.name)
} }
} }
// shift primary fronter to first in list // shift primary fronter to first in list
let primary = await findPrimary() let primary = await findPrimary()
if (primary) { let primaryPK = primary.pkId
if (newFront.indexOf(primary) > 0) { let primaryName = primary.name
newFront.splice(newFront.indexOf(primary), 1) if (primaryPK) {
newFront.unshift(primary) if (newFront.indexOf(primaryPK) > 0) {
newFront.splice(newFront.indexOf(primaryPK), 1)
newFront.unshift(primaryPK)
}
if (frontNames.indexOf(primaryName) > 0) {
frontNames.splice(frontNames.indexOf(primaryName), 1)
frontNames.unshift(primaryName)
} }
} }
@ -146,7 +155,8 @@ async function swapFront() {
await swapFront() await swapFront()
return return
} else { } else {
console.log('::SimplyWS:: SP\'s front has been published to PK.') let formattedNames = frontNames.toString().replace(',',', ')
console.log(`::SimplyWS:: SimplyPlural -> PluralKit: ${formattedNames}`)
} }
}) })
.catch(async err => { .catch(async err => {
@ -180,7 +190,7 @@ async function insertFront(member) {
} }
// find the "primary" fronter to move to the first element in the list // find the "primary" fronter to move to the first element in the list
let primary = await findPrimary() let primary = await findPrimary().pkId
if (primary) { if (primary) {
if (fronters.indexOf(primary) > 0) { if (fronters.indexOf(primary) > 0) {
fronters.splice(fronters.indexOf(primary), 1) fronters.splice(fronters.indexOf(primary), 1)
@ -241,11 +251,11 @@ async function removeFront(member) {
} }
// find the "primary" fronter to move to the first element in the list // find the "primary" fronter to move to the first element in the list
let p = await findPrimary() let primary = await findPrimary().pkId
if (p) { if (primary) {
if (fronters.indexOf(p) > 0) { if (fronters.indexOf(primary) > 0) {
fronters.splice(fronters.indexOf(p), 1) fronters.splice(fronters.indexOf(primary), 1)
fronters.unshift(p) fronters.unshift(primary)
} }
} }
@ -285,7 +295,7 @@ async function removeFront(member) {
async function updateCustomStatus(member) { async function updateCustomStatus(member) {
// find the "primary" fronter to move to the first element in the list // find the "primary" fronter to move to the first element in the list
let fronters = await getPKFronters() let fronters = await getPKFronters()
let primary = await findPrimary() let primary = await findPrimary().pkId
if (primary && fronters.length > 1 && (member.content.pkId == primary)) { if (primary && fronters.length > 1 && (member.content.pkId == primary)) {
if (fronters.indexOf(primary) >= 0) { if (fronters.indexOf(primary) >= 0) {
fronters.splice(fronters.indexOf(primary), 1) fronters.splice(fronters.indexOf(primary), 1)