mirror of
https://github.com/unraid/api.git
synced 2026-04-25 16:58:38 -05:00
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
/*!
|
|
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
|
* Written by: Alexis Tyler
|
|
*/
|
|
|
|
import { CoreContext, CoreResult } from '../types';
|
|
import { AppError, NotImplementedError } from '../errors';
|
|
import { sharesState, slotsState } from '../states';
|
|
import { ensurePermission } from '../utils';
|
|
|
|
export const addShare = async (context: CoreContext): Promise<CoreResult> => {
|
|
const { user, data } = context;
|
|
|
|
if (!data?.name) {
|
|
throw new AppError('No name provided');
|
|
}
|
|
|
|
// Check permissions
|
|
ensurePermission(user, {
|
|
resource: 'share',
|
|
action: 'create',
|
|
possession: 'any'
|
|
});
|
|
|
|
const name: string = data.name;
|
|
const userShares = sharesState.find().map(({ name }) => name);
|
|
const diskShares = slotsState.find({ exportable: 'yes' }).filter(({ name }) => name.startsWith('disk')).map(({ name }) => name);
|
|
|
|
// Existing share names
|
|
const inUseNames = new Set([
|
|
...userShares,
|
|
...diskShares
|
|
]);
|
|
|
|
if (inUseNames.has(name)) {
|
|
throw new AppError(`Share already exists with name: ${name}`, 400);
|
|
}
|
|
|
|
throw new NotImplementedError();
|
|
};
|