8 Commits

Author SHA1 Message Date
Sonny
d360a9044c chore: release v2.2.0 2024-10-07 02:26:00 +02:00
Sonny
8b4e5740d7 refactor: fix lucid warning 2024-10-07 02:24:27 +02:00
Sonny
c8fb5af44d feat: add user last seen field 2024-10-07 02:07:39 +02:00
Sonny
24cea2b0b2 chore: use vscode nesting system 2024-10-07 01:37:39 +02:00
Sonny
eea9732100 refactor: use tabs instead of spaces 2024-10-07 01:33:59 +02:00
Sonny
f425decf2c chore: rename compose files and use major release tag for postgres and pgadmin 2024-10-07 01:30:18 +02:00
Sonny
8b57f6dd47 chore(deps): update deps 2024-10-07 01:19:37 +02:00
Sonny
dda6fc299a chore: release v2.1.3 2024-09-18 17:01:49 +02:00
212 changed files with 6374 additions and 6079 deletions

View File

@@ -3,7 +3,7 @@
root = true
[*]
indent_style = space
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
@@ -17,8 +17,5 @@ insert_final_newline = unset
indent_style = unset
insert_final_newline = unset
[MakeFile]
indent_style = space
[*.md]
trim_trailing_whitespace = false

View File

@@ -1,13 +1,13 @@
{
"typescript.preferences.importModuleSpecifier": "non-relative",
/* Prefer tabs over spaces for accessibility */
"editor.insertSpaces": true,
"editor.insertSpaces": false,
"editor.detectIndentation": false,
/* Explorer */
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.js": "${capture}.js.map, ${capture}.min.js, ${capture}.d.ts",
"package.json": "package-lock.json, yarn.lock, pnpm-lock.yaml, rollup.config.mjs, tsconfig.json, eslint.config.js",
"Makefile": "*compose.yml, Dockerfile, .dockerignore, *startup.sh"
"package.json": "pnpm-lock.yaml, tsconfig.json, eslint.config.js, .babelrc, vite.config.ts, .editorconfig",
"Makefile": "*compose.yml, Dockerfile, servers_pgadmin.json, .dockerignore"
}
}

View File

@@ -53,10 +53,9 @@ ENV PORT=$PORT
WORKDIR /app
COPY --from=production-deps /app/node_modules /app/node_modules
COPY --from=build /app/build /app
COPY --from=build /app/startup.sh /app/startup.sh
# Expose port
EXPOSE $PORT
# Start app
CMD node bin/console.js migration:run --force && sh startup.sh
CMD node bin/console.js migration:run --force && node bin/server.js

View File

@@ -1,11 +1,13 @@
dev:
@docker compose down
@docker compose -f dev.docker-compose.yml up -d --wait
@docker compose -f dev.compose.yml pull
@docker compose -f dev.compose.yml up -d --wait
@node ace migration:fresh
@./dev.startup.sh
@pnpm run dev
prod:
@docker compose -f dev.docker-compose.yml down
@docker compose -f dev.compose.yml down
@docker compose pull
@docker compose up -d --build --wait
seed:
@@ -13,7 +15,7 @@ seed:
down:
@-docker compose down
@-docker compose -f dev.docker-compose.yml down
@-docker compose -f dev.compose.yml down
release:
@pnpm run release

View File

@@ -14,7 +14,6 @@ export default defineConfig({
() => import('@adonisjs/core/commands'),
() => import('@adonisjs/lucid/commands'),
() => import('@izzyjs/route/commands'),
() => import('adonisjs-scheduler/commands'),
],
/*
@@ -46,10 +45,6 @@ export default defineConfig({
() => import('@adonisjs/ally/ally_provider'),
() => import('@izzyjs/route/izzy_provider'),
() => import('#providers/route_provider'),
{
file: () => import('adonisjs-scheduler/scheduler_provider'),
environment: ['console'],
},
],
/*
@@ -60,14 +55,7 @@ export default defineConfig({
| List of modules to import before starting the application.
|
*/
preloads: [
() => import('#start/routes'),
() => import('#start/kernel'),
{
file: () => import('#start/scheduler'),
environment: ['console'],
},
],
preloads: [() => import('#start/routes'), () => import('#start/kernel')],
/*
|--------------------------------------------------------------------------

View File

@@ -16,10 +16,9 @@ class UserWithRelationCountDto {
isAdmin: this.user.isAdmin,
createdAt: this.user.createdAt,
updatedAt: this.user.updatedAt,
count: {
link: Number(this.user.$extras.totalLinks),
collection: Number(this.user.$extras.totalCollections),
},
lastSeenAt: this.user.lastSeenAt,
linksCount: Number(this.user.$extras.totalLinks),
collectionsCount: Number(this.user.$extras.totalCollections),
});
}

View File

@@ -4,8 +4,6 @@ import logger from '@adonisjs/core/services/logger';
import db from '@adonisjs/lucid/services/db';
import { RouteName } from '@izzyjs/route/types';
const INACTIVE_USER_THRESHOLD = 7;
export default class UsersController {
private redirectTo: RouteName = 'auth.login';
@@ -77,18 +75,4 @@ export default class UsersController {
.withCount('collections', (q) => q.as('totalCollections'))
.withCount('links', (q) => q.as('totalLinks'));
}
async getAllInactiveUsers() {
const users = await this.getAllUsersWithTotalRelations();
const inactiveUsers = users.filter((user) => {
const totalLinks = Number(user.$extras.totalLinks);
const totalCollections = Number(user.$extras.totalCollections);
const isOlderThan7Days =
Math.abs(user.updatedAt.diffNow('days').days) > INACTIVE_USER_THRESHOLD;
return (totalLinks === 0 || totalCollections === 0) && isOlderThan7Days;
});
return inactiveUsers ?? [];
}
}

View File

@@ -0,0 +1,9 @@
import type { HttpContext } from '@adonisjs/core/http';
import type { NextFn } from '@adonisjs/core/types/http';
export default class SilentAuthMiddleware {
async handle(ctx: HttpContext, next: NextFn) {
await ctx.auth.check();
return next();
}
}

View File

@@ -0,0 +1,16 @@
import type { HttpContext } from '@adonisjs/core/http';
import type { NextFn } from '@adonisjs/core/types/http';
import { DateTime } from 'luxon';
export default class UpdateUserLastSeenMiddleware {
async handle(ctx: HttpContext, next: NextFn) {
const user = ctx.auth.user;
if (user) {
user.lastSeenAt = DateTime.local();
await user.save();
}
const output = await next();
return output;
}
}

View File

@@ -4,6 +4,7 @@ import type { GoogleToken } from '@adonisjs/ally/types';
import { column, computed, hasMany } from '@adonisjs/lucid/orm';
import type { HasMany } from '@adonisjs/lucid/types/relations';
import AppBaseModel from './app_base_model.js';
import { DateTime } from 'luxon';
export default class User extends AppBaseModel {
@column()
@@ -44,4 +45,10 @@ export default class User extends AppBaseModel {
get fullname() {
return this.nickName || this.name;
}
@column.dateTime({
autoCreate: true,
autoUpdate: true,
})
declare lastSeenAt: DateTime;
}

View File

@@ -1,18 +0,0 @@
import UsersController from '#controllers/users_controller';
import { inject } from '@adonisjs/core';
import { BaseCommand } from '@adonisjs/core/ace';
import type { CommandOptions } from '@adonisjs/core/types/ace';
export default class RemoveInactiveUsers extends BaseCommand {
static commandName = 'remove:inactive-users';
static description = '';
static options: CommandOptions = {};
@inject()
async run(usersController: UsersController) {
const inactiveUsers = await usersController.getAllInactiveUsers();
await Promise.all(inactiveUsers.map((user) => user.delete()));
console.log(`Removed ${inactiveUsers.length} inactive users`);
}
}

View File

@@ -17,7 +17,7 @@ services:
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:8.6
image: dpage/pgadmin4:8
restart: always
healthcheck:
test: ['CMD', 'wget', '-O', '-', 'http://localhost:80/misc/ping']

View File

@@ -5,7 +5,14 @@ export default class CreateUsersTable extends BaseSchema {
static tableName = 'users';
async up() {
this.schema.createTableIfNotExists(CreateUsersTable.tableName, (table) => {
const exists = await this.schema.hasTable(CreateUsersTable.tableName);
if (exists) {
return console.warn(
`Table ${CreateUsersTable.tableName} already exists.`
);
}
this.schema.createTable(CreateUsersTable.tableName, (table) => {
table.string('email', 254).notNullable().unique();
table.string('name', 254).notNullable();
table.string('nick_name', 254).nullable();

View File

@@ -8,9 +8,14 @@ export default class CreateCollectionTable extends BaseSchema {
async up() {
this.schema.raw(`DROP TYPE IF EXISTS ${this.visibilityEnumName}`);
this.schema.createTableIfNotExists(
CreateCollectionTable.tableName,
(table) => {
const exists = await this.schema.hasTable(CreateCollectionTable.tableName);
if (exists) {
return console.warn(
`Table ${CreateCollectionTable.tableName} already exists.`
);
}
this.schema.createTable(CreateCollectionTable.tableName, (table) => {
table.string('name', 254).notNullable();
table.string('description', 254).nullable();
table
@@ -33,8 +38,7 @@ export default class CreateCollectionTable extends BaseSchema {
.onDelete('CASCADE');
defaultTableFields(table);
}
);
});
}
async down() {

View File

@@ -5,7 +5,13 @@ export default class CreateLinksTable extends BaseSchema {
static tableName = 'links';
async up() {
this.schema.createTableIfNotExists(CreateLinksTable.tableName, (table) => {
const exists = await this.schema.hasTable(CreateLinksTable.tableName);
if (exists) {
return console.warn(`Table ${CreateLinksTable.tableName} already
exists.`);
}
this.schema.createTable(CreateLinksTable.tableName, (table) => {
table.string('name', 254).notNullable();
table.string('description', 254).nullable();
table.text('url').notNullable();

View File

@@ -0,0 +1,15 @@
import { BaseSchema } from '@adonisjs/lucid/schema';
export default class extends BaseSchema {
protected tableName = 'users';
async up() {
this.schema.alterTable(this.tableName, (table) => {
table.timestamp('last_seen_at');
});
}
async down() {
this.schema.dropTable(this.tableName);
}
}

View File

@@ -17,7 +17,7 @@ services:
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4:8.6
image: dpage/pgadmin4:8
restart: always
environment:
- PGADMIN_DEFAULT_EMAIL=myemail@gmail.com

View File

@@ -1,6 +0,0 @@
#!/bin/bash
(trap 'kill 0' SIGINT; node ace scheduler:run & pnpm run dev)
wait -n
exit $?

View File

@@ -6,6 +6,7 @@ import {
getPaginationRowModel,
getSortedRowModel,
PaginationState,
SortingState,
useReactTable,
} from '@tanstack/react-table';
import { useState } from 'react';
@@ -50,13 +51,19 @@ const Resizer = styled.div<{ isResizing: boolean }>(
type TableProps<T> = {
columns: ColumnDef<T>[];
data: T[];
defaultSorting?: SortingState;
};
export default function Table<T>({ columns, data }: TableProps<T>) {
export default function Table<T>({
columns,
data,
defaultSorting = [],
}: TableProps<T>) {
const [pagination, setPagination] = useState<PaginationState>({
pageIndex: 0,
pageSize: 10,
});
const [sorting, setSorting] = useState<SortingState>(defaultSorting);
const table = useReactTable({
data,
@@ -65,11 +72,13 @@ export default function Table<T>({ columns, data }: TableProps<T>) {
columnResizeMode: 'onChange',
state: {
pagination,
sorting,
},
onPaginationChange: setPagination,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
onSortingChange: setSorting,
debugTable: true,
});

View File

@@ -1,7 +1,7 @@
{
"role": "Role",
"created_at": "Created at",
"updated_at": "Updated at",
"last_seen_at": "Last seen at",
"admin": "Administrator",
"user": "User",
"users": "Users",

View File

@@ -1,7 +1,7 @@
{
"role": "Rôle",
"created_at": "Création",
"updated_at": "Mise à jour",
"last_seen_at": "Dernière connexion",
"admin": "Administrateur",
"user": "Utilisateur",
"users": "Utilisateurs",

View File

@@ -51,7 +51,7 @@ function AdminDashboard({
[
{
accessorKey: 'id',
header: (
header: () => (
<>
# <span css={{ color: theme.colors.grey }}>({users.length})</span>
</>
@@ -69,8 +69,8 @@ function AdminDashboard({
cell: (info) => info.getValue(),
},
{
accessorKey: 'count',
header: (
accessorKey: 'collectionsCount',
header: () => (
<>
{t('common:collection.collections', { count: totalCollections })}{' '}
<span css={{ color: theme.colors.grey }}>
@@ -78,17 +78,17 @@ function AdminDashboard({
</span>
</>
),
cell: (info) => (info.getValue() as any)?.collection,
cell: (info) => info.getValue(),
},
{
accessorKey: 'count',
header: (
accessorKey: 'linksCount',
header: () => (
<>
{t('common:link.links', { count: totalLinks })}{' '}
<span css={{ color: theme.colors.grey }}>({totalLinks})</span>
</>
),
cell: (info: any) => info.getValue()?.link,
cell: (info: any) => info.getValue(),
},
{
accessorKey: 'isAdmin',
@@ -110,12 +110,23 @@ function AdminDashboard({
cell: RenderDateCell,
},
{
accessorKey: 'updatedAt',
header: t('admin:updated_at'),
accessorKey: 'lastSeenAt',
header: t('admin:last_seen_at'),
cell: RenderDateCell,
},
] as ColumnDef<UserWithRelationCount>[],
] satisfies ColumnDef<UserWithRelationCount>[],
[]
);
return <Table columns={columns} data={users} />;
return (
<Table
columns={columns}
data={users}
defaultSorting={[
{
id: 'lastSeenAt',
desc: true,
},
]}
/>
);
}

View File

@@ -24,10 +24,9 @@ type UserWithRelationCount = CommonBase & {
fullname: string;
avatarUrl: string;
isAdmin: string;
count: {
link: number;
collection: number;
};
linksCount: number;
collectionsCount: number;
lastSeenAt: string;
};
type Link = CommonBase & {

View File

@@ -1,6 +1,6 @@
{
"name": "my-links",
"version": "2.1.2",
"version": "2.2.0",
"type": "module",
"license": "UNLICENSED",
"scripts": {
@@ -33,8 +33,7 @@
"#tests/*": "./tests/*.js",
"#start/*": "./start/*.js",
"#config/*": "./config/*.js",
"#lib/*": "./app/lib/*.js",
"#routes/*": "./start/routes/*.js"
"#lib/*": "./app/lib/*.js"
},
"devDependencies": {
"@adonisjs/assembler": "^7.8.2",
@@ -42,56 +41,55 @@
"@adonisjs/prettier-config": "^1.4.0",
"@adonisjs/tsconfig": "^1.4.0",
"@emotion/babel-plugin": "^11.12.0",
"@faker-js/faker": "^9.0.1",
"@faker-js/faker": "^9.0.3",
"@japa/assert": "^3.0.0",
"@japa/plugin-adonisjs": "^3.0.1",
"@japa/runner": "^3.1.4",
"@swc/core": "^1.7.26",
"@types/luxon": "^3.4.2",
"@types/node": "^20.14.10",
"@types/react": "^18.3.7",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.0",
"@types/react-toggle": "^4.0.5",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^9.10.0",
"hot-hook": "^0.2.6",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@vitejs/plugin-react": "^4.3.2",
"eslint": "^9.12.0",
"hot-hook": "^0.3.0",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
"pino-pretty": "^11.2.2",
"prettier": "^3.3.3",
"release-it": "^17.6.0",
"release-it": "^17.7.0",
"ts-node-maintained": "^10.9.4",
"typescript": "~5.6.2",
"vite": "^5.4.6"
"typescript": "~5.5.4",
"vite": "^5.4.8"
},
"dependencies": {
"@adonisjs/ally": "^5.0.2",
"@adonisjs/auth": "^9.2.3",
"@adonisjs/core": "^6.13.1",
"@adonisjs/core": "^6.14.0",
"@adonisjs/cors": "^2.2.1",
"@adonisjs/inertia": "^1.1.0",
"@adonisjs/inertia": "^1.2.2",
"@adonisjs/lucid": "^21.2.0",
"@adonisjs/session": "^7.4.2",
"@adonisjs/session": "^7.5.0",
"@adonisjs/shield": "^8.1.1",
"@adonisjs/static": "^1.1.1",
"@adonisjs/vite": "^3.0.0",
"@emotion/react": "11.12.0",
"@emotion/styled": "^11.13.0",
"@inertiajs/react": "^1.2.0",
"@izzyjs/route": "^1.1.0-0",
"@izzyjs/route": "^1.2.0",
"@tanstack/react-table": "^8.20.5",
"@vinejs/vine": "^2.1.0",
"adonisjs-scheduler": "^1.0.5",
"bentocache": "^1.0.0-beta.9",
"dayjs": "^1.11.13",
"edge.js": "^6.0.2",
"edge.js": "^6.2.0",
"hex-rgb": "^5.0.0",
"i18next": "^23.15.1",
"i18next": "^23.15.2",
"knex": "^3.1.0",
"luxon": "^3.5.0",
"node-html-parser": "^6.1.13",
"pg": "^8.12.0",
"pg": "^8.13.0",
"react": "^18.3.1",
"react-dnd": "^16.0.1",
"react-dnd-html5-backend": "^16.0.1",
@@ -99,7 +97,7 @@
"react-hotkeys-hook": "^4.5.1",
"react-i18next": "^15.0.2",
"react-icons": "^5.3.0",
"react-select": "^5.8.0",
"react-select": "^5.8.1",
"react-swipeable": "^7.0.1",
"react-toggle": "^4.1.3",
"reflect-metadata": "^0.2.2"
@@ -114,7 +112,7 @@
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"useTabs": false,
"useTabs": true,
"quoteProps": "as-needed",
"bracketSpacing": true,
"arrowParens": "always",

2042
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,8 @@ router.use([
() => import('@adonisjs/session/session_middleware'),
() => import('@adonisjs/shield/shield_middleware'),
() => import('@adonisjs/auth/initialize_auth_middleware'),
() => import('#middleware/silent_auth_middleware'),
() => import('#middleware/update_user_last_seen_middleware'),
]);
/**

View File

@@ -1,8 +1,8 @@
import '#routes/admin';
import '#routes/app';
import '#routes/auth';
import '#routes/collection';
import '#routes/favicon';
import '#routes/link';
import '#routes/search';
import '#routes/shared_collection';
import './routes/admin.js';
import './routes/app.js';
import './routes/auth.js';
import './routes/collection.js';
import './routes/favicon.js';
import './routes/link.js';
import './routes/search.js';
import './routes/shared_collection.js';

View File

@@ -1,3 +0,0 @@
import scheduler from 'adonisjs-scheduler/services/main';
scheduler.command('remove:inactive-users').cron('0 20 * * *');

View File

@@ -1,6 +0,0 @@
#!/bin/bash
(trap 'kill 0' SIGINT; node ace scheduler:run & pnpm start)
wait -n
exit $?