Skip to content

Commit

Permalink
Merge pull request #54 from GregoryGost/develop
Browse files Browse the repository at this point in the history
v3.1.0
  • Loading branch information
GregoryGost authored Nov 27, 2024
2 parents 1a27592 + 02a30ec commit a1497d5
Show file tree
Hide file tree
Showing 30 changed files with 1,482 additions and 31,300 deletions.
32 changes: 9 additions & 23 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"plugins": ["jest", "@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:github/recommended",
"plugin:jest/recommended"
],
Expand All @@ -31,41 +30,28 @@
"i18n-text/no-en": "off",
"import/no-namespace": "off",
"no-console": "warn",
"no-unused-vars": "off",
"prettier/prettier": "error",
"semi": "off",
"@typescript-eslint/space-before-function-paren": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", { "accessibility": "no-public" }],
"@typescript-eslint/explicit-function-return-type": ["error", { "allowExpressions": true }],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"@typescript-eslint/semi": "off",
"@typescript-eslint/space-before-function-paren": "off",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
"@typescript-eslint/require-array-sort-compare": "error"
}
}
6 changes: 2 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ updates:
directory: /
target-branch: 'develop'
schedule:
interval: weekly
day: sunday
interval: monthly
time: '09:00'
timezone: 'Europe/Moscow'
labels:
Expand All @@ -22,8 +21,7 @@ updates:
directory: /
target-branch: 'develop'
schedule:
interval: weekly
day: sunday
interval: monthly
time: '09:00'
timezone: 'Europe/Moscow'
labels:
Expand Down
32 changes: 9 additions & 23 deletions .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ plugins:

extends:
- eslint:recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:@typescript-eslint/recommended-type-checked
- plugin:github/recommended
- plugin:jest/recommended

Expand All @@ -42,40 +41,27 @@ rules:
'i18n-text/no-en': 'off',
'import/no-namespace': 'off',
'no-console': 'warn',
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'semi': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/explicit-member-accessibility': ['error', { 'accessibility': 'no-public' }],
'@typescript-eslint/explicit-function-return-type': ['error', { 'allowExpressions': true }],
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'warn',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-for-of': 'warn',
'@typescript-eslint/prefer-function-type': 'warn',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/promise-function-async': 'error',
'@typescript-eslint/require-array-sort-compare': 'error',
'@typescript-eslint/restrict-plus-operands': 'error',
'@typescript-eslint/semi': 'off',
'@typescript-eslint/space-before-function-paren': 'off',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/unbound-method': 'error'
'@typescript-eslint/require-array-sort-compare': 'error'
}
2 changes: 2 additions & 0 deletions .github/workflows/check-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
- name: Compare Directories
id: diff
run: |
echo "Compare Directories"
git config core.filemode false
if [ ! -d dist/ ]; then
echo "Expected dist/ directory does not exist. See status below:"
ls -la ./
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/develop-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: New tag step
id: new-dev-version
uses: GregoryGost/version-tagger@v1.0.4
uses: GregoryGost/version-tagger@v1.0.5
with:
token: ${{ secrets.GITHUB_TOKEN }}
prefix: 'v'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main-versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: New tag step
id: new-main-version
uses: GregoryGost/version-tagger@v1.0.4
uses: GregoryGost/version-tagger@v1.0.5
with:
token: ${{ secrets.GITHUB_TOKEN }}
prefix: 'v'
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ __tests__/runner/*
config.json

# Old files dir
old/
old/
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

История версий:

- v3.1.0 - (27.11.2024) Переход на инструмент сборки бандла TSUP. Изменение config.
- v3.0.2 - (04.10.2024) 100% покрытие тестами. Исправление регулярного выражения для получения информации о торрент
файле.
- v3.0.1 - (29.09.2024) Поддержка актуальности библиотек.
Expand Down Expand Up @@ -96,15 +97,14 @@ node -v
v20.17.0
```

Далее создаем папку под приложение, делаем файл исполняемым. Создаем фейковый файл `package.json` (нужно для корректного
определения корневой дирректории и нахождения файла конфигурации)
Далее создаем папку под приложение, скачиваем файлы `index.js` и `package.json`. Делаем файл `index.js` исполняемым.

```shell
mkdir /opt/torrentclear
cd /opt/torrentclear
wget https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/main/dist/index.js
wget -O index.js https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/main/dist/index.js
wget -O package.json https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/main/package.json
chmod +x index.js
echo '{"version":"3.0.2"}' > package.json
```

### Конфигурирование
Expand Down Expand Up @@ -214,16 +214,18 @@ bash nodesource_setup.sh
apt update && apt upgrade -y
```

Для обновления можно просто перекачать `index.js` файл
Для обновления можно просто перекачать файлы `index.js` и `package.json`

```shell
wget -O index.js https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/main/dist/index.js
wget -O package.json https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/main/package.json
```

Если вы хотите обновить из другой ветки, просто поменяйте её название в пути скачивания
Если вы хотите обновить из другой ветки, просто поменяйте её название в пути скачивания. Пример для ветки `develop`

```shell
wget -O index.js https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/develop/dist/index.js
wget -O package.json https://raw.githubusercontent.com/GregoryGost/transmission-torrentclear/refs/heads/develop/package.json
```

## Ротация логов
Expand Down Expand Up @@ -260,9 +262,9 @@ systemctl status logrotate.service
проекта не дает никаких гарантий на работоспособность исполняемых файлов, а так же не несет никакой ответственности по
искам или за нанесенный ущерб.

Этот репозиторий содержит ссылки на все используемые модули и их лицензии. Они собраны в
[специальный файл лицензий](./dist/licenses.txt). Их авторы самостоятельно несут (или не несут) ответственность за
качество, стабильность и работу этих модулей.
Этот репозиторий содержит сторонние модули. Авторы этих модулей самостоятельно несут (или не несут) ответственность за
качество, стабильность и работу этих модулей и их принципы лицензирования. Используемые модули находятся в зависимостях
в файле `package.json`

## Немного о себе

Expand Down
2 changes: 1 addition & 1 deletion __tests__/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!configs/config.json
!configs/no_login/config.json
!configs/no_tr_env/config.json
!configs/ak_prod/config.json
!configs/ak_prod/config.json
16 changes: 8 additions & 8 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Unit tests for src/class/config.ts
*/
import { cwd } from 'node:process';
import { normalize, join } from 'node:path';
import { normalize, join, resolve } from 'node:path';
//
import { Config } from '../src/class/config';

Expand All @@ -14,39 +14,39 @@ describe('config.ts', () => {
/**
* Instance test
*/
it('config instance', async () => {
it('config instance', () => {
const testRootPath: string = normalize(join(cwd(), '__tests__', 'configs'));
const config: Config = new Config(testRootPath);
expect(config instanceof Config).toBe(true);
});
/**
* Throw exceptions
*/
it('config init error settings file', async () => {
it('config init error config file', () => {
// no config file
try {
new Config();
} catch (error) {
// eslint-disable-next-line jest/no-conditional-expect
expect(error).toHaveProperty(
'message',
`Transmission settings file not found on path ${normalize('/etc/transmission-daemon/settings.json')}`
`File not found on path "${normalize(join(cwd(), 'config.json'))}" or relative path "${resolve(normalize(join(cwd(), 'config.json')))}"`
);
}
});
it('config init error login', async () => {
it('config init error login', () => {
const testRootPath: string = normalize(join(cwd(), '__tests__', 'configs', 'no_login'));
try {
new Config(testRootPath);
} catch (error) {
// eslint-disable-next-line jest/no-conditional-expect
expect(error).toHaveProperty('message', 'Login or password must be filled in config.json file or Environment');
expect(error).toHaveProperty('message', 'Parameter "login" incorrect value "undefined" of type "undefined"');
}
});
/**
* Get all parameters test
*/
it('get base parameters', async () => {
it('get base parameters', () => {
const testRootPath: string = normalize(join(cwd(), '__tests__', 'configs'));
const config: Config = new Config(testRootPath);
//
Expand All @@ -65,7 +65,7 @@ describe('config.ts', () => {
expect(config.limitTime).toBe(100000);
expect(config.settingsFilePath).toBe('./__tests__/settings.json');
});
it('get specific parameters if prod', async () => {
it('get specific parameters if prod', () => {
const testRootPath: string = normalize(join(cwd(), '__tests__', 'configs', 'ak_prod'));
const config: Config = new Config(testRootPath);
//
Expand Down
2 changes: 1 addition & 1 deletion __tests__/configs/ak_prod/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"password": "1234567890123456789",
"settings_file_path": "./__tests__/settings.json",
"log_file_path": "./torrentclear_prod.log"
}
}
2 changes: 1 addition & 1 deletion __tests__/configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"limit_time": 100000,
"settings_file_path": "./__tests__/settings.json",
"cron_expression": "0 1 * * *"
}
}
2 changes: 1 addition & 1 deletion __tests__/configs/no_login/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"password": "password",
"log_file_path": "./logs/torrentclone.log",
"settings_file_path": "./__tests__/settings.json"
}
}
3 changes: 3 additions & 0 deletions __tests__/configs/no_login/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "99.99.99"
}
2 changes: 1 addition & 1 deletion __tests__/configs/no_tr_env/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
"password": "password",
"log_file_path": "./logs/torrentclear.log",
"settings_file_path": "./__tests__/settings.json"
}
}
19 changes: 16 additions & 3 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@ let mainMock: jest.SpyInstance;
describe('index.ts', () => {
beforeEach(() => {
mainMock = jest.spyOn(Torrentclear.prototype, 'main').mockImplementation();
jest.spyOn(Config.prototype, 'check').mockImplementation();
jest.spyOn(Config.prototype, 'settingsFileExists').mockImplementation();
jest.spyOn(Config.prototype, 'getParam').mockImplementation((param_name: string): string => {
if (param_name === 'node_env') return 'production';
if (param_name === 'log_level') return 'info';
if (param_name === 'log_file_path') return '/var/log/transmission/torrentclear.log';
if (param_name === 'date_format') return 'DD.MM.YYYY_HH:mm:ss';
if (param_name === 'log_date_format') return 'dd.MM.yyyy_hh:mm:ss.SSS';
if (param_name === 'ip_address') return '127.0.0.1';
if (param_name === 'tcp_port') return '9091';
if (param_name === 'limit_time') return '604800';
if (param_name === 'login') return 'mock_login';
if (param_name === 'password') return 'mock_password';
if (param_name === 'settings_file_path') return '/etc/transmission-daemon/settings.json';
return '';
});
jest.spyOn(Config.prototype, 'checkFileExists').mockImplementation();
// fix EACCES: permission denied, mkdir '/var/log/transmission'
jest.spyOn(Config.prototype, 'logFilePath', 'get').mockReturnValue('./var/log/transmission');
});
afterEach(() => {
jest.clearAllMocks();
});
it('Torrentclear main run', async () => {
it('Torrentclear main run', () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('../src/index');
expect(mainMock).toHaveBeenCalled();
Expand Down
Loading

0 comments on commit a1497d5

Please sign in to comment.