1fichier
v1.0.2
Published
A typescript client for the 1fichier API
Readme
1fichier-ts
A fully-typed TypeScript client for the 1fichier.com API. Supports all endpoints from the official OpenAPI spec, including file upload/download, folder management, user info, remote upload, and vouchers.
Features
- Full coverage of 1fichier.com API endpoints
- TypeScript types for all request/response schemas
- Modern async/await API
- Built-in authentication via API key
- Axios-based HTTP client
- Easy to extend and test
Installation
npm install 1fichierUsage
Basic Example
import FichierApiClient from "1fichier";
const client = new FichierApiClient("YOUR_API_KEY");
// Generate a download token
const token = await client.getDownloadToken({ url: "https://1fichier.com/?example" });
console.log(token.url);
// List files in root folder
const files = await client.listFiles({ folder_id: 0 });
console.log(files.items);Authentication
All requests require a valid API key. Pass your API key when constructing the client:
const client = new FichierApiClient("YOUR_API_KEY");API Reference
File Operations
getDownloadToken(data)- Generate a download token for a filegetFileInfo(data)- Get detailed info about a filelistFiles(data)- List files in a folderscanFile(data)- Scan a file for virusesremoveFiles(data)- Remove filesmoveFiles(data)- Move filesrenameFiles(data)- Rename filescopyFiles(data)- Copy fileschangeFileAttr(data)- Change file attributes
Upload
getUploadServer(pretty)- Get optimal upload serveruploadFiles(formData)- Upload files (multipart/form-data)getUploadResult(xid)- Get upload result
Folder Operations
listFolders(data)- List folderscreateFolder(data)- Create a foldershareFolder(data)- Share a foldermoveFolder(data)- Move a folderremoveFolder(data)- Remove a folder
User
getUserInfo(data)- Get/set account info
Remote Upload
listRemoteUploads()- List remote uploadsgetRemoteUploadInfo(id)- Get remote upload inforequestRemoteUpload(data)- Request remote upload
Vouchers
listVouchers()- List unused voucherscheckVoucher(data)- Check voucher validityuseVoucher(data)- Use voucher
TypeScript Types
All request and response schemas are fully typed. See src/types.ts for details.
Error Handling
All methods throw on HTTP/network errors. Use try/catch for error handling:
try {
const info = await client.getFileInfo({ url: "https://1fichier.com/?example" });
} catch (err) {
console.error("API error", err);
}Testing
Unit tests are provided using Vitest. Run tests with:
npm testContributing
Contributions are welcome! To contribute:
- Fork the repo and create your branch.
- Write clear, tested code. Add/modify tests in
src/index.test.ts. - Ensure all types are correct and documented.
- Open a pull request with a detailed description.
Development Setup
git clone https://github.com/nunsie/1fichier-ts.git
cd 1fichier-ts
npm install
npm testCoding Standards
- Use TypeScript strict mode
- Document all public methods
- Prefer async/await
- Write unit tests for new features
License
MIT © 2025 Nusrath Khan
