mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-09 23:15:36 +00:00
Compare commits
7 Commits
2.1.0
...
remove_ina
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05f067a430 | ||
|
|
b0e3bfa0f6 | ||
|
|
9d4eb08bc9 | ||
|
|
f8e7e7cd64 | ||
|
|
cda3a89f32 | ||
|
|
ed4dbca329 | ||
|
|
f8a92b7219 |
@@ -1,4 +1 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
. "$(dirname -- "$0")/_/husky.sh"
|
|
||||||
|
|
||||||
npx lint-staged
|
npx lint-staged
|
||||||
|
|||||||
12
.vscode/settings.json
vendored
12
.vscode/settings.json
vendored
@@ -1,3 +1,13 @@
|
|||||||
{
|
{
|
||||||
"typescript.preferences.importModuleSpecifier": "non-relative"
|
"typescript.preferences.importModuleSpecifier": "non-relative",
|
||||||
|
/* Prefer tabs over spaces for accessibility */
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
"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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,9 +53,10 @@ ENV PORT=$PORT
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=production-deps /app/node_modules /app/node_modules
|
COPY --from=production-deps /app/node_modules /app/node_modules
|
||||||
COPY --from=build /app/build /app
|
COPY --from=build /app/build /app
|
||||||
|
COPY --from=build /app/startup.sh /app/startup.sh
|
||||||
|
|
||||||
# Expose port
|
# Expose port
|
||||||
EXPOSE $PORT
|
EXPOSE $PORT
|
||||||
|
|
||||||
# Start app
|
# Start app
|
||||||
CMD node bin/console.js migration:run --force && node bin/server.js
|
CMD node bin/console.js migration:run --force && sh startup.sh
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -2,7 +2,7 @@ dev:
|
|||||||
@docker compose down
|
@docker compose down
|
||||||
@docker compose -f dev.docker-compose.yml up -d --wait
|
@docker compose -f dev.docker-compose.yml up -d --wait
|
||||||
@node ace migration:fresh
|
@node ace migration:fresh
|
||||||
@pnpm run dev
|
@./dev.startup.sh
|
||||||
|
|
||||||
prod:
|
prod:
|
||||||
@docker compose -f dev.docker-compose.yml down
|
@docker compose -f dev.docker-compose.yml down
|
||||||
|
|||||||
3
ace.js
3
ace.js
@@ -19,8 +19,7 @@
|
|||||||
/**
|
/**
|
||||||
* Register hook to process TypeScript files using ts-node
|
* Register hook to process TypeScript files using ts-node
|
||||||
*/
|
*/
|
||||||
import { register } from 'node:module';
|
import 'ts-node-maintained/register/esm';
|
||||||
register('ts-node/esm', import.meta.url);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import ace console entrypoint
|
* Import ace console entrypoint
|
||||||
|
|||||||
14
adonisrc.ts
14
adonisrc.ts
@@ -14,6 +14,7 @@ export default defineConfig({
|
|||||||
() => import('@adonisjs/core/commands'),
|
() => import('@adonisjs/core/commands'),
|
||||||
() => import('@adonisjs/lucid/commands'),
|
() => import('@adonisjs/lucid/commands'),
|
||||||
() => import('@izzyjs/route/commands'),
|
() => import('@izzyjs/route/commands'),
|
||||||
|
() => import('adonisjs-scheduler/commands'),
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -45,6 +46,10 @@ export default defineConfig({
|
|||||||
() => import('@adonisjs/ally/ally_provider'),
|
() => import('@adonisjs/ally/ally_provider'),
|
||||||
() => import('@izzyjs/route/izzy_provider'),
|
() => import('@izzyjs/route/izzy_provider'),
|
||||||
() => import('#providers/route_provider'),
|
() => import('#providers/route_provider'),
|
||||||
|
{
|
||||||
|
file: () => import('adonisjs-scheduler/scheduler_provider'),
|
||||||
|
environment: ['console'],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -55,7 +60,14 @@ export default defineConfig({
|
|||||||
| List of modules to import before starting the application.
|
| List of modules to import before starting the application.
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
preloads: [() => import('#start/routes'), () => import('#start/kernel')],
|
preloads: [
|
||||||
|
() => import('#start/routes'),
|
||||||
|
() => import('#start/kernel'),
|
||||||
|
{
|
||||||
|
file: () => import('#start/scheduler'),
|
||||||
|
environment: ['console'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ export default class CollectionsController {
|
|||||||
return response.redirectToNamedRoute('dashboard');
|
return response.redirectToNamedRoute('dashboard');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Create DTOs
|
||||||
return inertia.render('dashboard', {
|
return inertia.render('dashboard', {
|
||||||
collections,
|
collections: collections.map((collection) => collection.serialize()),
|
||||||
activeCollection: activeCollection || collections[0],
|
activeCollection:
|
||||||
|
activeCollection?.serialize() || collections[0].serialize(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import logger from '@adonisjs/core/services/logger';
|
|||||||
import db from '@adonisjs/lucid/services/db';
|
import db from '@adonisjs/lucid/services/db';
|
||||||
import { RouteName } from '@izzyjs/route/types';
|
import { RouteName } from '@izzyjs/route/types';
|
||||||
|
|
||||||
|
const INACTIVE_USER_THRESHOLD = 7;
|
||||||
|
|
||||||
export default class UsersController {
|
export default class UsersController {
|
||||||
private redirectTo: RouteName = 'auth.login';
|
private redirectTo: RouteName = 'auth.login';
|
||||||
|
|
||||||
@@ -75,4 +77,18 @@ export default class UsersController {
|
|||||||
.withCount('collections', (q) => q.as('totalCollections'))
|
.withCount('collections', (q) => q.as('totalCollections'))
|
||||||
.withCount('links', (q) => q.as('totalLinks'));
|
.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 ?? [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
commands/remove_inactive_users.ts
Normal file
18
commands/remove_inactive_users.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
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`);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
dev.startup.sh
Executable file
6
dev.startup.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
(trap 'kill 0' SIGINT; node ace scheduler:run & pnpm run dev)
|
||||||
|
|
||||||
|
wait -n
|
||||||
|
exit $?
|
||||||
4
eslint.config.js
Normal file
4
eslint.config.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { configApp } from '@adonisjs/eslint-config';
|
||||||
|
export default configApp({
|
||||||
|
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
||||||
|
});
|
||||||
@@ -80,6 +80,7 @@ export default function DashboardProviders(
|
|||||||
enabled: globalHotkeysEnabled,
|
enabled: globalHotkeysEnabled,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CollectionsContext.Provider value={collectionsContextValue}>
|
<CollectionsContext.Provider value={collectionsContextValue}>
|
||||||
<ActiveCollectionContext.Provider value={activeCollectionContextValue}>
|
<ActiveCollectionContext.Provider value={activeCollectionContextValue}>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const SearchItemStyle = styled('li', {
|
|||||||
shouldForwardProp: (propName) => propName !== 'isActive',
|
shouldForwardProp: (propName) => propName !== 'isActive',
|
||||||
})<{ isActive: boolean }>(({ theme, isActive }) => ({
|
})<{ isActive: boolean }>(({ theme, isActive }) => ({
|
||||||
fontSize: '16px',
|
fontSize: '16px',
|
||||||
backgroundColor: isActive ? theme.colors.background : 'transparent',
|
backgroundColor: isActive ? theme.colors.secondary : 'transparent',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '0.35em',
|
gap: '0.35em',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { appendCollectionId, appendLinkId } from '~/lib/navigation';
|
|||||||
import { LinkWithCollection } from '~/types/app';
|
import { LinkWithCollection } from '~/types/app';
|
||||||
|
|
||||||
const FavoriteItemStyle = styled(ItemExternalLink)(({ theme }) => ({
|
const FavoriteItemStyle = styled(ItemExternalLink)(({ theme }) => ({
|
||||||
|
height: 'auto',
|
||||||
backgroundColor: theme.colors.secondary,
|
backgroundColor: theme.colors.secondary,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -23,13 +24,20 @@ const FavoriteDropdown = styled(Dropdown)(({ theme }) => ({
|
|||||||
backgroundColor: theme.colors.secondary,
|
backgroundColor: theme.colors.secondary,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const FavoriteContainer = styled.div({
|
||||||
|
flex: 1,
|
||||||
|
lineHeight: '1.1rem',
|
||||||
|
});
|
||||||
|
|
||||||
export default function FavoriteItem({ link }: { link: LinkWithCollection }) {
|
export default function FavoriteItem({ link }: { link: LinkWithCollection }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<FavoriteItemStyle href={link.url}>
|
<FavoriteItemStyle href={link.url}>
|
||||||
<LinkFavicon url={link.url} size={24} />
|
<LinkFavicon url={link.url} size={24} />
|
||||||
|
<FavoriteContainer>
|
||||||
<TextEllipsis>{link.name}</TextEllipsis>
|
<TextEllipsis>{link.name}</TextEllipsis>
|
||||||
<Legend>({link.collection.name})</Legend>
|
<Legend>{link.collection.name}</Legend>
|
||||||
|
</FavoriteContainer>
|
||||||
<FavoriteDropdown
|
<FavoriteDropdown
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const ProfileStyle = styled(UnstyledList)({
|
|||||||
gap: '1.25em',
|
gap: '1.25em',
|
||||||
});
|
});
|
||||||
|
|
||||||
const Column = styled.li({
|
const Column = styled.div({
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
gap: '1rem',
|
gap: '1rem',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
|
|||||||
48
package.json
48
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "my-links",
|
"name": "my-links",
|
||||||
"version": "2.1.0",
|
"version": "2.1.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"build": "node ace build",
|
"build": "node ace build",
|
||||||
"dev": "node ace serve --watch",
|
"dev": "node ace serve --watch",
|
||||||
"test": "node ace test",
|
"test": "node ace test",
|
||||||
"lint": "eslint . --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0",
|
"lint": "eslint . --report-unused-disable-directives --max-warnings 0",
|
||||||
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
"format": "prettier --write --parser typescript '**/*.{ts,tsx}'",
|
||||||
"typecheck": "tsc --noEmit",
|
"typecheck": "tsc --noEmit",
|
||||||
"prepare": "husky",
|
"prepare": "husky",
|
||||||
@@ -33,40 +33,42 @@
|
|||||||
"#tests/*": "./tests/*.js",
|
"#tests/*": "./tests/*.js",
|
||||||
"#start/*": "./start/*.js",
|
"#start/*": "./start/*.js",
|
||||||
"#config/*": "./config/*.js",
|
"#config/*": "./config/*.js",
|
||||||
"#lib/*": "./app/lib/*.js"
|
"#lib/*": "./app/lib/*.js",
|
||||||
|
"#routes/*": "./start/routes/*.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@adonisjs/assembler": "^7.7.0",
|
"@adonisjs/assembler": "^7.8.2",
|
||||||
"@adonisjs/eslint-config": "^1.3.0",
|
"@adonisjs/eslint-config": "2.0.0-beta.6",
|
||||||
"@adonisjs/tsconfig": "^1.3.0",
|
"@adonisjs/prettier-config": "^1.4.0",
|
||||||
|
"@adonisjs/tsconfig": "^1.4.0",
|
||||||
"@emotion/babel-plugin": "^11.12.0",
|
"@emotion/babel-plugin": "^11.12.0",
|
||||||
"@faker-js/faker": "^8.4.1",
|
"@faker-js/faker": "^9.0.1",
|
||||||
"@japa/assert": "^3.0.0",
|
"@japa/assert": "^3.0.0",
|
||||||
"@japa/plugin-adonisjs": "^3.0.1",
|
"@japa/plugin-adonisjs": "^3.0.1",
|
||||||
"@japa/runner": "^3.1.4",
|
"@japa/runner": "^3.1.4",
|
||||||
"@swc/core": "^1.7.22",
|
"@swc/core": "^1.7.26",
|
||||||
"@types/luxon": "^3.4.2",
|
"@types/luxon": "^3.4.2",
|
||||||
"@types/node": "^20.14.10",
|
"@types/node": "^20.14.10",
|
||||||
"@types/react": "^18.3.5",
|
"@types/react": "^18.3.7",
|
||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@types/react-toggle": "^4.0.5",
|
"@types/react-toggle": "^4.0.5",
|
||||||
"@typescript-eslint/eslint-plugin": "^7.15.0",
|
"@typescript-eslint/eslint-plugin": "^8.6.0",
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^9.10.0",
|
||||||
"hot-hook": "^0.2.6",
|
"hot-hook": "^0.2.6",
|
||||||
"husky": "^9.1.5",
|
"husky": "^9.1.6",
|
||||||
"lint-staged": "^15.2.9",
|
"lint-staged": "^15.2.10",
|
||||||
"pino-pretty": "^11.2.2",
|
"pino-pretty": "^11.2.2",
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"release-it": "^17.6.0",
|
"release-it": "^17.6.0",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node-maintained": "^10.9.4",
|
||||||
"typescript": "~5.5.4",
|
"typescript": "~5.6.2",
|
||||||
"vite": "^5.4.2"
|
"vite": "^5.4.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@adonisjs/ally": "^5.0.2",
|
"@adonisjs/ally": "^5.0.2",
|
||||||
"@adonisjs/auth": "^9.2.3",
|
"@adonisjs/auth": "^9.2.3",
|
||||||
"@adonisjs/core": "^6.12.1",
|
"@adonisjs/core": "^6.13.1",
|
||||||
"@adonisjs/cors": "^2.2.1",
|
"@adonisjs/cors": "^2.2.1",
|
||||||
"@adonisjs/inertia": "^1.1.0",
|
"@adonisjs/inertia": "^1.1.0",
|
||||||
"@adonisjs/lucid": "^21.2.0",
|
"@adonisjs/lucid": "^21.2.0",
|
||||||
@@ -74,17 +76,18 @@
|
|||||||
"@adonisjs/shield": "^8.1.1",
|
"@adonisjs/shield": "^8.1.1",
|
||||||
"@adonisjs/static": "^1.1.1",
|
"@adonisjs/static": "^1.1.1",
|
||||||
"@adonisjs/vite": "^3.0.0",
|
"@adonisjs/vite": "^3.0.0",
|
||||||
"@emotion/react": "^11.13.3",
|
"@emotion/react": "11.12.0",
|
||||||
"@emotion/styled": "^11.13.0",
|
"@emotion/styled": "^11.13.0",
|
||||||
"@inertiajs/react": "^1.2.0",
|
"@inertiajs/react": "^1.2.0",
|
||||||
"@izzyjs/route": "^1.1.0-0",
|
"@izzyjs/route": "^1.1.0-0",
|
||||||
"@tanstack/react-table": "^8.20.5",
|
"@tanstack/react-table": "^8.20.5",
|
||||||
"@vinejs/vine": "^2.1.0",
|
"@vinejs/vine": "^2.1.0",
|
||||||
|
"adonisjs-scheduler": "^1.0.5",
|
||||||
"bentocache": "^1.0.0-beta.9",
|
"bentocache": "^1.0.0-beta.9",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"edge.js": "^6.0.2",
|
"edge.js": "^6.0.2",
|
||||||
"hex-rgb": "^5.0.0",
|
"hex-rgb": "^5.0.0",
|
||||||
"i18next": "^23.14.0",
|
"i18next": "^23.15.1",
|
||||||
"knex": "^3.1.0",
|
"knex": "^3.1.0",
|
||||||
"luxon": "^3.5.0",
|
"luxon": "^3.5.0",
|
||||||
"node-html-parser": "^6.1.13",
|
"node-html-parser": "^6.1.13",
|
||||||
@@ -93,8 +96,8 @@
|
|||||||
"react-dnd": "^16.0.1",
|
"react-dnd": "^16.0.1",
|
||||||
"react-dnd-html5-backend": "^16.0.1",
|
"react-dnd-html5-backend": "^16.0.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-hotkeys-hook": "^4.5.0",
|
"react-hotkeys-hook": "^4.5.1",
|
||||||
"react-i18next": "^14.1.2",
|
"react-i18next": "^15.0.2",
|
||||||
"react-icons": "^5.3.0",
|
"react-icons": "^5.3.0",
|
||||||
"react-select": "^5.8.0",
|
"react-select": "^5.8.0",
|
||||||
"react-swipeable": "^7.0.1",
|
"react-swipeable": "^7.0.1",
|
||||||
@@ -107,9 +110,6 @@
|
|||||||
"./app/middleware/*.ts"
|
"./app/middleware/*.ts"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
|
||||||
"extends": "@adonisjs/eslint-config/app"
|
|
||||||
},
|
|
||||||
"prettier": {
|
"prettier": {
|
||||||
"trailingComma": "es5",
|
"trailingComma": "es5",
|
||||||
"semi": true,
|
"semi": true,
|
||||||
|
|||||||
2769
pnpm-lock.yaml
generated
2769
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
|||||||
import './routes/admin.js';
|
import '#routes/admin';
|
||||||
import './routes/app.js';
|
import '#routes/app';
|
||||||
import './routes/auth.js';
|
import '#routes/auth';
|
||||||
import './routes/collection.js';
|
import '#routes/collection';
|
||||||
import './routes/favicon.js';
|
import '#routes/favicon';
|
||||||
import './routes/link.js';
|
import '#routes/link';
|
||||||
import './routes/search.js';
|
import '#routes/search';
|
||||||
import './routes/shared_collection.js';
|
import '#routes/shared_collection';
|
||||||
|
|||||||
3
start/scheduler.ts
Normal file
3
start/scheduler.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import scheduler from 'adonisjs-scheduler/services/main';
|
||||||
|
|
||||||
|
scheduler.command('remove:inactive-users').cron('0 20 * * *');
|
||||||
6
startup.sh
Executable file
6
startup.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
(trap 'kill 0' SIGINT; node ace scheduler:run & pnpm start)
|
||||||
|
|
||||||
|
wait -n
|
||||||
|
exit $?
|
||||||
Reference in New Issue
Block a user