Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
supersonictw committed May 19, 2024
1 parent f048ea2 commit ff0364e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Node.js & TypeScript",
"image": "mcr.microsoft.com/devcontainers/typescript-node:1-18-bookworm",
"forwardPorts": [3000]
}
11 changes: 6 additions & 5 deletions .github/workflows/build.yml → .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create and publish a Docker image
name: Main workflow

on:
push:
Expand All @@ -11,30 +11,31 @@ env:

jobs:
build-and-push-image:
name: Build and publish a Docker image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
Expand Down
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
FROM node:16-alpine
FROM node:18

ENV RUNTIME_ENV container

RUN useradd -u 3000 recv

RUN mkdir -p \
/home/recv \
/workplace

RUN mkdir -p /workplace
WORKDIR /workplace
ADD . /workplace

RUN chown -R \
3000:3000 \
/home/recv \
/workplace

USER 3000
RUN npm install

EXPOSE 3000
CMD ["npm", "start"]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"@line/bot-sdk": "^9.2.2",
"@matrix-org/matrix-sdk-crypto-nodejs": "0.1.0-beta.6",
"axios": "^1.6.8",
"dotenv": "^16.4.5",
"express": "^4.19.2",
Expand Down
11 changes: 10 additions & 1 deletion src/provider/matrix/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import {
MatrixClient,
SimpleFsStorageProvider,
RustSdkCryptoStorageProvider,
} from "matrix-bot-sdk";

import {
StoreType,
} from "@matrix-org/matrix-sdk-crypto-nodejs";

const dataDirectoryPath = `${__dirname}/../../../data`;

export const homeserverUrl = process.env.MATRIX_HOMESERVER_URL || "";
export const accessToken = process.env.MATRIX_ACCESS_TOKEN || "";
export const storage = new SimpleFsStorageProvider(
`${dataDirectoryPath}/bot.json`,
`${dataDirectoryPath}/storage.json`,
);
export const crypto = new RustSdkCryptoStorageProvider(
`${dataDirectoryPath}/crypto`,
StoreType.Sled,
);

export const client = new MatrixClient(
Expand Down
5 changes: 3 additions & 2 deletions src/provider/matrix/listener/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
MatrixClient,
} from "matrix-bot-sdk";
Expand All @@ -7,7 +8,6 @@ import {
*/
export class MatrixListenerClient extends MatrixClient {
identity?: string;
e2eeMode?: boolean;

/**
* Starts syncing the client with an optional filter
Expand All @@ -16,7 +16,8 @@ export class MatrixListenerClient extends MatrixClient {
*/
async start(filter?: any): Promise<any> {
this.identity = await this.getUserId();
this.e2eeMode = false;
const joinedRooms = await this.getJoinedRooms();
await this.crypto.prepare(joinedRooms);
return await super.start(filter);
}
}
2 changes: 2 additions & 0 deletions src/provider/matrix/listener/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
homeserverUrl,
accessToken,
storage,
crypto,
} from "../index";

import roomMessage from "./room_message";
Expand All @@ -18,6 +19,7 @@ const listenerClient = new MatrixListenerClient(
homeserverUrl,
accessToken,
storage,
crypto,
);

AutojoinRoomsMixin.setupOnClient(listenerClient);
Expand Down

0 comments on commit ff0364e

Please sign in to comment.