mirror of
https://github.com/VueTorrent/VueTorrent.git
synced 2024-11-24 18:36:14 +03:00
feat: basic fake torrent generator #518
This commit is contained in:
parent
60ecfc547b
commit
d3cda1a649
10 changed files with 88 additions and 4 deletions
2
.env.development
Normal file
2
.env.development
Normal file
|
@ -0,0 +1,2 @@
|
|||
VITE_USE_FAKE_TORRENTS=true
|
||||
VITE_FAKE_TORRENT_COUNT=30
|
2
.github/workflows/nightly.yml
vendored
2
.github/workflows/nightly.yml
vendored
|
@ -23,7 +23,7 @@ jobs:
|
|||
run: npm ci
|
||||
- name: Build VueTorrent
|
||||
run: npm run build
|
||||
- name: Push to latest-release
|
||||
- name: Push to nightly-release
|
||||
uses: JamesIves/github-pages-deploy-action@3.7.1
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
@ -74,6 +74,7 @@ If you like to always have the latest and greatest, please sync to the `nightly-
|
|||
- `npm run lint` (to format the code)
|
||||
- `docker-compose up -d` (to start qbittorrent docker => optional, you can edit `vite.config.js` as well)
|
||||
- Open the WebUI on localhost with the default username `admin` and password `adminadmin`.
|
||||
- Edit `env.development` to tweak your dev environment (e.g. fake torrents)
|
||||
|
||||
## Features
|
||||
|
||||
|
|
17
package-lock.json
generated
17
package-lock.json
generated
|
@ -27,6 +27,7 @@
|
|||
"vuex-persist": "^3.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^7.6.0",
|
||||
"@mdi/js": "^5.9.55",
|
||||
"@types/jsdom": "^20.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5",
|
||||
|
@ -1833,6 +1834,16 @@
|
|||
"url": "https://opencollective.com/eslint"
|
||||
}
|
||||
},
|
||||
"node_modules/@faker-js/faker": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-7.6.0.tgz",
|
||||
"integrity": "sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=14.0.0",
|
||||
"npm": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@humanwhocodes/config-array": {
|
||||
"version": "0.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.7.tgz",
|
||||
|
@ -8969,6 +8980,12 @@
|
|||
"strip-json-comments": "^3.1.1"
|
||||
}
|
||||
},
|
||||
"@faker-js/faker": {
|
||||
"version": "7.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-7.6.0.tgz",
|
||||
"integrity": "sha512-XK6BTq1NDMo9Xqw/YkYyGjSsg44fbNwYRx7QK2CuoQgyy+f1rrTDHoExVM5PsyXCtfl2vs2vVJ0MN0yN6LppRw==",
|
||||
"dev": true
|
||||
},
|
||||
"@humanwhocodes/config-array": {
|
||||
"version": "0.11.7",
|
||||
"resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.7.tgz",
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
"vuex-persist": "^3.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^7.6.0",
|
||||
"@mdi/js": "^5.9.55",
|
||||
"@types/jsdom": "^20.0.1",
|
||||
"@typescript-eslint/eslint-plugin": "^5",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import store from '../store'
|
||||
import { Hostname } from '@/Helpers/index.js'
|
||||
import Torrent from '@/models/Torrent'
|
||||
import { isProduction } from '../utils'
|
||||
import { generateMultiple } from '../utils/faker'
|
||||
|
||||
export class Torrents {
|
||||
static update(data) {
|
||||
|
@ -12,7 +14,13 @@ export class Torrents {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(data)
|
||||
// update torrents
|
||||
store.state.torrents = data.map(t => new Torrent(t))
|
||||
|
||||
// load fake torrents if enabled
|
||||
if(isProduction() && !import.meta.env.VITE_USE_FAKE_TORRENTS) return
|
||||
const count = import.meta.env.VITE_FAKE_TORRENT_COUNT
|
||||
store.state.torrents.push(...generateMultiple(count))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/* eslint-disable no-unused-vars */
|
||||
import { isProduction } from './utils'
|
||||
|
||||
export function formatBytes(a, b) {
|
||||
if (a == 0) return '0 B'
|
||||
const c = 1024
|
||||
|
@ -150,7 +151,7 @@ export function stringContainsUrl(string) {
|
|||
}
|
||||
|
||||
export function getVersion() {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (isProduction()) {
|
||||
return 'import.meta.env.VITE_PACKAGE_VERSION'
|
||||
}
|
||||
|
||||
|
@ -158,7 +159,7 @@ export function getVersion() {
|
|||
}
|
||||
|
||||
export function getBaseURL() {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (isProduction()) {
|
||||
return 'import.meta.env.BASE_URL'
|
||||
}
|
||||
|
||||
|
|
15
src/utils/faker.spec.ts
Normal file
15
src/utils/faker.spec.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { describe, it, expect } from 'vitest'
|
||||
import { generateMultiple, generateTorrent } from './faker'
|
||||
|
||||
describe('faker to generate fake torrents', () => {
|
||||
it('can generate a fake torrent', () => {
|
||||
const t = generateTorrent({ name: 'Test' })
|
||||
expect(t.name).toBe('Test')
|
||||
})
|
||||
|
||||
it('can generate multile', () => {
|
||||
const ts = generateMultiple(3)
|
||||
expect(ts.length).toBe(3)
|
||||
expect(ts[0]?.name).toBe('Torrent - 0')
|
||||
})
|
||||
})
|
32
src/utils/faker.ts
Normal file
32
src/utils/faker.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { faker } from '@faker-js/faker'
|
||||
import Torrent from '../models/Torrent'
|
||||
|
||||
export function generateMultiple(count: number = 1): Torrent[] {
|
||||
const torrents: Torrent[] = []
|
||||
for (let i = 0; i < count; i++) {
|
||||
torrents.push(
|
||||
generateTorrent({
|
||||
name: 'Torrent - ' + i
|
||||
})
|
||||
)
|
||||
}
|
||||
return torrents
|
||||
}
|
||||
|
||||
export function generateTorrent(data: any): Torrent {
|
||||
return new Torrent({
|
||||
name: data.name,
|
||||
size: faker.datatype.number({ min: 1000000, max: 50000000000 }),
|
||||
tags: [],
|
||||
progress: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
|
||||
state: faker.helpers.arrayElement(['done', 'downloading', 'fail', 'paused', 'queued', 'seeding', 'checking', 'stalled', 'metadata', 'moving']),
|
||||
eta: faker.datatype.number({ min: 1000, max: 900000 }),
|
||||
availability: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
|
||||
added_on: faker.date.recent(),
|
||||
ratio: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
|
||||
num_leechs: faker.datatype.number({ min: 0, max: 500 }),
|
||||
available_seeds: faker.datatype.number({ min: 0, max: 500 }),
|
||||
num_seeds: faker.datatype.number({ min: 0, max: 500 }),
|
||||
available_peers: faker.datatype.number({ min: 0, max: 500 }),
|
||||
})
|
||||
}
|
7
src/utils/index.ts
Normal file
7
src/utils/index.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
export function isProduction(): boolean {
|
||||
return process.env.NODE_ENV === 'production'
|
||||
}
|
||||
|
||||
export function isDevelopment(): boolean {
|
||||
return process.env.NODE_ENV === 'development'
|
||||
}
|
Loading…
Reference in a new issue