Skip to content

Commit

Permalink
Merge pull request #185 from konecty/refactor/lookup-reference
Browse files Browse the repository at this point in the history
Refactor Konsistent & Add db transactions
  • Loading branch information
7sete7 authored Nov 14, 2024
2 parents 3043202 + 4221ffa commit 9a3241f
Show file tree
Hide file tree
Showing 38 changed files with 1,657 additions and 1,246 deletions.
15 changes: 15 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
KONECTY_MODE=development
MONGO_URL= #mongodb://localhost:27023/clientname?directConnection=true

DISABLE_REINDEX=true
ALLOWED_ORIGINS=http://localhost:3000|http://localhost:5173

LOG_REQUEST=true
LOG_LEVEL=trace
LOG_TO_FILE=kon.log

KONMETA_NAMESPACE= #clientname
UI_URL=https://ui.konecty.com

BLOB_URL=http://localhost:3001
PREVIEW_URL=http://localhost:3001
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ RUN yarn install --production --silent --non-interactive --frozen-lockfile


RUN addgroup -g 1001 -S nodejs
RUN adduser -S konecty -u 1001
RUN adduser -S konecty -u 1001 --ingroup nodejs

USER konecty:nodejs

USER konecty
ENV PORT=3000
ENV NODE_ENV production
ENV NODE_ICU_DATA=/app/node_modules/full-icu
Expand Down
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@

# Konecty Open source Tech Business Platform

## How to run local/development

You will need a mongodb database (you can use a free account at cloud.mongodb.com or a local mongodb install)

Create .env using the sample.

Fill MONGO_URL with your database url, adding authentication and options

MONGO_URL=mongodb+srv://login:password@konecty.mongodb.net/?appName=konecty

```
yarn
yarn start
```

If this is a empty database, basic metadata and starting collections will be automatically created.

The UI will be running at `localhost:3000`

## Konecty environment variables

- `KONECTY_MODE`: Can be `production` or `development`
- `DISABLE_KONSISTENT`: can be to `true` if you don't want Konsistent to run on the same process as Kondata. It's enabled by default.
- `MONGO_URL`: Mongo database URL
- `MONGO_OPLOG_URL`: Mongo database oplog URL
- `DISABLE_REINDEX`: can be to `true` if you don't want to verify if all index are created.
- `ROOT_URL`: your public url
- `ALLOWED_ORIGINS`: a list of cors alloweds URLs separated by `|`
- `LOG_REQUEST=true`: if provide all requests are loggeds
- `DEFAULT_SMTP_HOST`: SMTP host for default email sender (**required**)
Expand Down Expand Up @@ -56,14 +73,12 @@ docker run --name kondata -p 3000:3000 --link mongo --env MONGO_URL=mongodb://mo

Examples of REST usage can be found here: [REST](REST.md)

## Logs
## Namespace configuration

- KONDATA only log requests when **_status code_** of the response isn't 200 (OK).
The namespace is made of many parts, documented at:

## DEVELOPMENT
- [Storage api](STORAGE.md)

```
sudo apt install build-essential
meteor npm install
meteor
```
## Logs

- KONDATA only log requests when **_status code_** of the response isn't 200 (OK).
79 changes: 79 additions & 0 deletions STORAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Storage API Configuration

This document describes the configuration for the storage API, including details on storage type, file management, and image processing settings.
The files api is [located here](./src/server/routes/rest/file/).

## Configuration Structure

The storage API configuration is part of the [Namespace](./src/imports/model/Namespace.ts) configuration. In any given deployment, it is located at the Namespace document: `MetaObjects > { "_id": "Namespace" }`, and is structured as the following example:

```json
{
"storage": {
"type": "local",
"directory": "/kon-files",
"wm": null,
"maxFileSize": 1073741824,
"thumbnail": {
"size": 200
},
"jpeg": {
"maxWidth": 3840,
"maxHeight": 3840,
"quality": 80
}
}
}
```

### Fields

- **type**: The type of storage being used. In this configuration, it is set to `"local"`, indicating that files are stored on the local filesystem. Its options can be:
- **s3**
- **local**
- **directory**: The directory where files will be stored, in the local filesystem. In this case, it is set to `"/kon-files"`.

- **wm**: This field is reserved for watermarking functionality. In this case set to `null` meaning no Watermark. The field type is described at [src/imports/types/watermark.ts](./src/imports/types/watermark.ts)

- **maxFileSize**: The maximum allowed file size for uploads, specified in bytes. Here, it is set to `1073741824` bytes (1 GB).

- **thumbnail**: Configuration for generating thumbnails.

- **size**: The size of the thumbnails, set to `200` pixels (width and height).

- **jpeg**: Configuration for processing JPEG images.
- **maxWidth**: The maximum width for JPEG images, set to `3840` pixels.
- **maxHeight**: The maximum height for JPEG images, set to `3840` pixels.
- **quality**: The quality of JPEG images after processing, with a value of `80` (on a scale from 0 to 100).

## Kubernetes CI YAML Configuration

When using the local filesystem, for deployment in a Kubernetes environment, the folder must be made a volume, so it can have the correct permissions.

```yaml
spec:
containers:
- name: konecty
image: konecty/konecty:2.1.9

(...)

volumeMounts:
- name: files-folder
mountPath: /kon-files

volumes:
- name: files-folder
emptyDir: {}
```
### Explanation
- **volumeMounts**: This section defines where the volumes should be mounted in the container.
- **name**: The name of the volume, here called `files-folder`.
- **mountPath**: The path inside the container where the volume should be mounted. This matches the directory in the storage configuration (`/kon-files`).

- **volumes**: This section defines the volumes available to the pod.
- **name**: The name of the volume, corresponding to the volume mount.
- **emptyDir**: This specifies that the volume is an empty directory, which exists only as long as the pod is running. It is used for temporary storage.
3 changes: 2 additions & 1 deletion src/imports/auth/geolocation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function saveGeoLocation({ authTokenId, longitude, latitude, userAg
return { success: false, errors: [{ message: 'Longitude or Latitude not defined' }] };
}

const user = getUser(authTokenId);
const user = await getUser(authTokenId);

const ua = new UAParser(userAgent ?? 'API Call').getResult();

Expand All @@ -30,6 +30,7 @@ export async function saveGeoLocation({ authTokenId, longitude, latitude, userAg
group: user.group,
},
],
__from: "setGeoLocation",
};

await MetaObject.Collections.AccessLog.insertOne(accessLog);
Expand Down
2 changes: 1 addition & 1 deletion src/imports/auth/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface UserInfoResponse {
name?: string;
namespace?: {
_id: string;
logoURL: string;
logoURL?: string;
siteURL: string;
title: string;
};
Expand Down
6 changes: 6 additions & 0 deletions src/imports/auth/login/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface accessLog {
resolution?: { width: number; height: number };
reason?: string;
source?: string;
__from?: string;
_user?: [
{
_id: string;
Expand All @@ -53,8 +54,13 @@ export async function login({ ip, user, password, password_SHA256, geolocation,
os: ua.os.name,
platform: ua.device.type,
source,
__from: 'login',
};

if (accessLog.source == null) {
delete accessLog.source;
}

if (resolution != null) {
if (typeof resolution === 'string') {
accessLog.resolution = JSON.parse(resolution);
Expand Down
3 changes: 3 additions & 0 deletions src/imports/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ export const DEFAULT_JPEG_MAX_SIZE = 3840;
export const DEFAULT_THUMBNAIL_SIZE = 200;
export const DEFAULT_EXPIRATION = 31536000;
export const ALLOWED_CORS_FILE_TYPES = ['png', 'jpg', 'gif', 'jpeg', 'webp'];

export const WRITE_TIMEOUT = 3e4; // 30 seconds
export const TRANSACTION_OPTIONS = { readConcern: { level: 'majority' }, writeConcern: { w: 'majority', wtimeoutMS: WRITE_TIMEOUT } };
Loading

0 comments on commit 9a3241f

Please sign in to comment.