Images, admin & errors
Using the lunar-js image shortcuts, admin resource, S3 helpers, and the LunarAPIError type.
Images, admin & errors
Images
One shortcut per image folder, or go through the resource directly:
// Top-level shortcuts (one per folder):
await client.fox();
await client.bird();
await client.shibe();
await client.weinerDog();
await client.slap();
await client.hug();
await client.kiss();
await client.pat();
await client.smug();
// Or use the resource directly:
await client.images.random('fox');
// The public proxy:
const url = client.images.proxyUrl('fox', 'example.png');
const { data, contentType } = await client.images.proxy('fox', 'example.png');The folders map 1
to the API's image routes; the proxy helpers wrap the image proxy.Admin
Requires a token whose role passes the route's priority check — see Roles & permissions.
await client.admin.ban({ username: 'winter_fe' });
await client.admin.searchUser({ username: 'winter_fe' });
await client.admin.users();
await client.admin.dashboard();
await client.admin.editRole({ username: 'winter_fe', role: 'support' });
await client.admin.editUsername({ username: 'winter_fe', newUsername: 'winter' });S3 object storage
await client.admin.s3.test('lunar-api');
await client.admin.s3.upload({
bucketName: 'lunar-api',
objectName: 'fox/example.png',
data: imageBytes, // ArrayBuffer | Uint8Array
contentType: 'image/png',
});
await client.admin.s3.delete({ bucketName: 'lunar-api', objectName: 'fox/example.png' });Error handling
Every method throws a LunarAPIError on failure. The Lunar API uses several error envelopes; the human-readable message is normalised from whichever shape came back, and the raw payload is preserved on error.body.
import { LunarAPIError } from 'lunar-js';
try {
await client.admin.users();
}
catch (error) {
if (error instanceof LunarAPIError) {
console.error(error.status, error.message, error.body);
}
}