Fs / setattr
TypeScript
Set file information. Errors: - ESTALE - The inode does not exist. - EFBIG - The target size is too large. - EISDIR - Attempted to resize a directory.
Request parameters
{
/** The model's id. */
modelId: string,
/** Inode number of file. */
inode: number,
/** If specified, file mode to set. */
mode?: number,
/** If specified the file will be resized to this size. */
size?: number,
/** If specified, set access time. */
atime?: {
sec: number,
nsec: number
},
/** If specified, set modified time. */
mtime?: {
sec: number,
nsec: number
}
}
Response
{
/** If successful. One of "result" and "error" will be present. */
result?: {
stat: Stat
},
/** If failed */
error?: {
code: 'model_not_found' | 'access_denied' | 'ESTALE' | 'EFBIG' | 'EISDIR' | 'bad_credentials' | 'too_many_requests' | 'payment_required' | 'unknown'
} | {
code: 'invalid_parameter',
parameterName: string,
reason: string
}
}
Where "Stat" is defined as:
export type Stat = {
mode: number,
nlink: number,
rdev: number,
size: number,
blksize: number,
blocks: number,
atime: number,
atime_nsec: number,
mtime: number,
mtime_nsec: number,
ctime: number,
ctime_nsec: number
}
Example
Following the installation guide to setup the Decthings API for TypeScript. Add your parameters to the following code and run it in Node.js, or in a browser by using a bundler.
The code reads your API key from file. Create an API key and save it to the file "auth.txt". Keep your key safe!
import * as fs from 'fs'
import { DecthingsClient } from '@decthings/api-client'
let apiKey = fs.readFileSync('./auth.txt').toString().trim()
let client = new DecthingsClient({ apiKey })
async function main() {
try {
let response = await client.fs.setattr({
modelId: /* Add modelId here */,
inode: /* Add inode here */
})
if (result.error) {
// Decthings sent us an error
console.log(response.error)
} else {
// Success!
console.log(response.result)
}
}
catch (e) {
// Client throws an error on connection issues. The function may or may not have succeded
console.log(e)
}
}
main()