Skip to content

About

Helper plugin for helping installing the remote assets into public dir.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@proj-airi/unplugin-fetch

Helper plugin for helping installing the remote assets into public dir.

Note

This project is part of (and also associate to) the Project AIRI, we aim to build a LLM-driven VTuber like Neuro-sama (subscribe if you didn't!) if you are interested in, please do give it a try on live demo.

Installation

Pick the package manager of your choice:

ni @proj-airi/unplugin-fetch -D # from @antfu/ni, can be installed via `npm i -g @antfu/ni`
pnpm i @proj-airi/unplugin-fetch -D
yarn i @proj-airi/unplugin-fetch -D
npm i @proj-airi/unplugin-fetch -D

UnoCSS usage

import { defineConfig } from 'vite'

import { Download } from '@proj-airi/unplugin-fetch/vite'

export default defineConfig({
  plugins: [
    Download('https://dist.ayaka.moe/live2d-models/hiyori_free_zh.zip', 'hiyori_free_zh.zip', 'assets/live2d/models'),
    Download('https://dist.ayaka.moe/live2d-models/hiyori_pro_zh.zip', 'hiyori_pro_zh.zip', 'assets/live2d/models'),
  ]
})

cacheDir and parentDir can be absolute paths if you want to share cache across packages (for example const sharedCacheDir = resolve(join(import.meta.dirname, '..', '..', '.cache'))). Absolute values are used as-is; relative values are resolved against config.root. When parentDir: false, assets are copied to config.root/<destination> instead of being skipped.

Progress and timeout

On an interactive terminal every download of one config shares a single line, rewritten in place, so a long transfer never looks stuck:

Downloading preload.data...
Downloading hiyori_free_zh.zip...
0/2 files   43% ██████████░░░░░░░░░░░░░░░░░░  1.3 MiB / 3.0 MiB  1.3 MiB/s  ETA 0:01
hiyori_free_zh.zip downloaded in 1.5s.
hiyori_free_zh.zip copied to /path/to/public.
preload.data   84% ██████████████████████░░░  2.6 MiB / 3.0 MiB  1.1 MiB/s  ETA 0:01
preload.data downloaded in 3.1s.
preload.data copied to /path/to/public.

The percentage counts the bytes of every file still downloading plus the ones that already finished, so one line covers the whole set even though the downloads run concurrently. When a server sends no content-length, the bar is replaced by a spinner and the received byte count. The line gives up detail before it wraps: the ETA goes first, then the speed and the total size, and only then is the file name shortened.

Terminals that implement the ConEmu/Windows Terminal progress sequence (OSC 9;4) additionally show the same progress in the tab header and on the taskbar, cleared once the downloads finish.

Output that is not a terminal — a pipe, CI, --silent, or a custom Vite logger — gets one line per file per second instead:

preload.data: 42% (95.1 MiB / 226.2 MiB)

idleTimeout aborts a download that stops sending data. It defaults to 30000 milliseconds. Only silence between chunks counts, so a slow link to a large file is not treated as a failure. Raise it when a server pauses for long stretches:

Download(url, 'preload.data', 'assets/models', { idleTimeout: 120_000 })

A download is written to <filename>.part and renamed when it completes. An interrupted download therefore leaves no file that a later run would treat as cached.

retries downloads the file again after a network error, a stall, a truncated body, or an HTTP 408, 425, 429, or 5xx status. It defaults to 3. The waits between attempts are 1 s, 2 s, 4 s, and so on. Other 4xx statuses, such as 404, fail at once:

Download(url, 'preload.data', 'assets/models', { retries: 5 })

Other side projects born from Project AIRI

About

Helper plugin for helping installing the remote assets into public dir.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages