[FEAT] update upload of data
This commit is contained in:
parent
57a48de52f
commit
263a4ae4c0
@ -78,6 +78,9 @@ public class MediaResource {
|
||||
if (data.contentEquals("null")) {
|
||||
return null;
|
||||
}
|
||||
if (data.contentEquals("undefined")) {
|
||||
return null;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -86,34 +89,43 @@ public class MediaResource {
|
||||
@Consumes({ MediaType.MULTIPART_FORM_DATA })
|
||||
@Operation(description = "Create a new Media", tags = "GLOBAL")
|
||||
@TypeScriptProgress
|
||||
public Media uploadFile( //
|
||||
@FormDataParam("fileName") String fileName, //
|
||||
@FormDataParam("universe") String universe, //
|
||||
@FormDataParam("series") String series, //
|
||||
// @FormDataParam("seriesId") String seriesId, // Not used ...
|
||||
@FormDataParam("season") String season, //
|
||||
@FormDataParam("episode") String episode, //
|
||||
@FormDataParam("title") String title, //
|
||||
public Media uploadMedia( //
|
||||
// @AsyncType(Long.class) @FormDataParam("universeId") String universeId, //
|
||||
// @AsyncType(Long.class) @FormDataParam("typeId") String typeId, //
|
||||
// @AsyncType(Long.class) @FormDataParam("seriesId") String seriesId, //
|
||||
// @AsyncType(Long.class) @FormDataParam("season") String season, // value of the season ==> local add if needed
|
||||
// @AsyncType(Long.class) @FormDataParam("episode") String episode, // value of the season ==> local add if needed
|
||||
@FormDataParam("universeId") String universeId, //
|
||||
@FormDataParam("typeId") String typeId, //
|
||||
@FormDataParam("seriesId") String seriesId, //
|
||||
@FormDataParam("season") String season, // value of the season ==> local add if needed
|
||||
@FormDataParam("episode") String episode, // value of the season ==> local add if needed
|
||||
@FormDataParam("title") String title, //
|
||||
@FormDataParam("file") final InputStream fileInputStream, //
|
||||
@FormDataParam("file") final FormDataContentDisposition fileMetaData //
|
||||
) throws FailException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
// correct input string stream :
|
||||
fileName = multipartCorrection(fileName);
|
||||
universe = multipartCorrection(universe);
|
||||
series = multipartCorrection(series);
|
||||
final String fileName = multipartCorrection(fileMetaData.getFileName());
|
||||
universeId = multipartCorrection(universeId);
|
||||
final Long universeIdLong = universeId != null ? Long.parseLong(universeId) : null;
|
||||
typeId = multipartCorrection(typeId);
|
||||
final Long typeIdLong = typeId != null ? Long.parseLong(typeId) : null;
|
||||
seriesId = multipartCorrection(seriesId);
|
||||
final Long seriesIdLong = seriesId != null ? Long.parseLong(seriesId) : null;
|
||||
season = multipartCorrection(season);
|
||||
final Long seasonLong = season != null ? Long.parseLong(season) : null;
|
||||
episode = multipartCorrection(episode);
|
||||
title = multipartCorrection(title);
|
||||
typeId = multipartCorrection(typeId);
|
||||
|
||||
// todo: check if all remotes Id exist ...
|
||||
|
||||
// public NodeSmall uploadFile(final FormDataMultiPart form) {
|
||||
LOGGER.info("Upload media file: {}", fileMetaData);
|
||||
LOGGER.info(" - fileName: {}", fileName);
|
||||
LOGGER.info(" - universe: {}", universe);
|
||||
LOGGER.info(" - series: {}", series);
|
||||
LOGGER.info(" - season: {}", season);
|
||||
LOGGER.info(" - universe: {}", universeIdLong);
|
||||
LOGGER.info(" - series: {}", seriesIdLong);
|
||||
LOGGER.info(" - season: {}", seasonLong);
|
||||
LOGGER.info(" - episode: {}", episode);
|
||||
LOGGER.info(" - title: {}", title);
|
||||
LOGGER.info(" - type: {}", typeId);
|
||||
@ -149,26 +161,32 @@ public class MediaResource {
|
||||
// Fist step: retieve all the Id of each parents:...
|
||||
LOGGER.info("Find typeNode");
|
||||
// check if id of type exist:
|
||||
final Type typeNode = TypeResource.getId(Long.parseLong(typeId));
|
||||
final Type typeNode = TypeResource.getId(typeIdLong);
|
||||
if (typeNode == null) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
throw new InputException("typeId", "TypeId does not exist ...");
|
||||
}
|
||||
LOGGER.info(" ==> {}", typeNode);
|
||||
LOGGER.info("Find seriesNode");
|
||||
// get uid of group:
|
||||
// check if id of type exist:
|
||||
Series seriesNode = null;
|
||||
if (series != null) {
|
||||
seriesNode = SeriesResource.getOrCreate(series, typeNode.id);
|
||||
if (seriesIdLong != null) {
|
||||
seriesNode = SeriesResource.getId(seriesIdLong);
|
||||
if (seriesNode == null) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
throw new InputException("seriesId", "seriesId does not exist ...");
|
||||
}
|
||||
if (seriesNode.parentId != typeNode.id) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
throw new InputException("seriesId", "seriesId object have not the correct parent...");
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info(" ==> {}", seriesNode);
|
||||
LOGGER.info("Find seasonNode");
|
||||
// get uid of season:
|
||||
Season seasonNode = null;
|
||||
if (seriesNode == null && season != null) {
|
||||
if (seriesNode == null && seasonLong != null) {
|
||||
DataResource.removeTemporaryFile(tmpUID);
|
||||
throw new InputException("season", "Season is set but no seraies is set !!");
|
||||
throw new InputException("season", "Season is set but no series is set !!");
|
||||
}
|
||||
if (season != null) {
|
||||
seasonNode = SeasonResource.getOrCreate(season, seriesNode.id);
|
||||
|
@ -52,6 +52,9 @@ public class SeriesResource {
|
||||
return DataAccess.get(Series.class, id);
|
||||
}
|
||||
|
||||
public static Series getId(final Long id) throws Exception {
|
||||
return DataAccess.get(Series.class, id);
|
||||
}
|
||||
/* ============================================================================= ADMIN SECTION: ============================================================================= */
|
||||
|
||||
@POST
|
||||
|
@ -34,6 +34,7 @@ public class Media extends GenericDataSoftDelete {
|
||||
public ObjectId dataId;
|
||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Data.class)
|
||||
@Column(nullable = false)
|
||||
@Nullable
|
||||
public UUID dataIdOld;
|
||||
@Schema(description = "Type of the media")
|
||||
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Type.class)
|
||||
|
@ -181,21 +181,20 @@ export namespace MediaResource {
|
||||
/**
|
||||
* Create a new Media
|
||||
*/
|
||||
export function uploadFile({
|
||||
export function uploadMedia({
|
||||
restConfig,
|
||||
data,
|
||||
callbacks,
|
||||
}: {
|
||||
restConfig: RESTConfig,
|
||||
data: {
|
||||
fileName: string,
|
||||
file: File,
|
||||
series: string,
|
||||
universe: string,
|
||||
universeId: string,
|
||||
season: string,
|
||||
episode: string,
|
||||
typeId: string,
|
||||
episode: string,
|
||||
title: string,
|
||||
seriesId: string,
|
||||
},
|
||||
callbacks?: RESTCallbacks,
|
||||
}): Promise<Media> {
|
||||
|
@ -22,7 +22,7 @@ export const ZodMedia = ZodGenericDataSoftDelete.extend({
|
||||
* Foreign Key Id of the data
|
||||
*/
|
||||
dataId: ZodObjectId,
|
||||
dataIdOld: ZodUUID,
|
||||
dataIdOld: ZodUUID.optional(),
|
||||
/**
|
||||
* Type of the media
|
||||
*/
|
||||
@ -79,7 +79,7 @@ export const ZodMediaWrite = ZodGenericDataSoftDeleteWrite.extend({
|
||||
* Foreign Key Id of the data
|
||||
*/
|
||||
dataId: ZodObjectId.optional(),
|
||||
dataIdOld: ZodUUID.optional(),
|
||||
dataIdOld: ZodUUID.nullable().optional(),
|
||||
/**
|
||||
* Type of the media
|
||||
*/
|
||||
|
@ -69,7 +69,8 @@ export const Covers = ({
|
||||
loading="lazy"
|
||||
src={url}
|
||||
maxWidth={size}
|
||||
boxSize={size} /*{...rest}*/
|
||||
maxHeight={size}
|
||||
boxSize={size}
|
||||
onClick={onClick}
|
||||
/>
|
||||
);
|
||||
|
@ -16,6 +16,8 @@ export type FormSelectProps = {
|
||||
placeholder?: string;
|
||||
// Form: Specify if the element is required or not
|
||||
isRequired?: boolean;
|
||||
// is locked for edition
|
||||
disabled?: boolean;
|
||||
// List of object options
|
||||
options: object[];
|
||||
// in the option specify the value Key
|
||||
@ -35,6 +37,7 @@ export const FormSelect = ({
|
||||
options,
|
||||
keyInputKey = 'id',
|
||||
keyInputValue = 'name',
|
||||
disabled = false,
|
||||
suggestion,
|
||||
addNewItem,
|
||||
...rest
|
||||
@ -60,6 +63,7 @@ export const FormSelect = ({
|
||||
keyValue={keyInputValue}
|
||||
onCreate={onCreate}
|
||||
suggestion={suggestion}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</FormGroup>
|
||||
);
|
||||
|
@ -73,7 +73,13 @@ export const PopUpUploadProgress = ({
|
||||
animated
|
||||
max={totalSize}
|
||||
height="24px"
|
||||
/>
|
||||
width="full"
|
||||
colorPalette="blue"
|
||||
>
|
||||
<Progress.Track>
|
||||
<Progress.Range />
|
||||
</Progress.Track>
|
||||
</Progress.Root>
|
||||
<Flex>
|
||||
<Text>{currentSize.toLocaleString('fr-FR')} Bytes</Text>
|
||||
<Text marginLeft="auto">
|
||||
@ -81,7 +87,7 @@ export const PopUpUploadProgress = ({
|
||||
</Text>
|
||||
</Flex>
|
||||
{error && (
|
||||
<Text fontWeight="bold" color="darkred">
|
||||
<Text fontWeight="bold" color="darkred" whiteSpace="pre-wrap">
|
||||
{error}
|
||||
</Text>
|
||||
)}
|
||||
|
@ -17,6 +17,8 @@ export type SelectSingleProps = {
|
||||
onChange?: (value: number | string | undefined) => void;
|
||||
keyKey?: string;
|
||||
keyValue?: string;
|
||||
// is locked for edition
|
||||
disabled?: boolean;
|
||||
ref?: RefObject<any>;
|
||||
// if set add capability to add the search item
|
||||
onCreate?: (data: string) => void;
|
||||
@ -31,6 +33,7 @@ export const SelectSingle = ({
|
||||
ref,
|
||||
keyKey = 'id',
|
||||
keyValue = keyKey,
|
||||
disabled = false,
|
||||
suggestion,
|
||||
onCreate,
|
||||
}: SelectSingleProps) => {
|
||||
@ -107,6 +110,7 @@ export const SelectSingle = ({
|
||||
<Flex>
|
||||
<Input
|
||||
ref={refFocus}
|
||||
disabled={disabled}
|
||||
width="full"
|
||||
onChange={(e) => onChangeInput(e.target.value)}
|
||||
onFocus={() => setShowList(true)}
|
||||
@ -124,6 +128,7 @@ export const SelectSingle = ({
|
||||
/>
|
||||
<Button
|
||||
onClick={onRemoveItem}
|
||||
disabled={disabled}
|
||||
variant="outline"
|
||||
borderRadius="0 5px 5px 0"
|
||||
borderWidth="1px 1px 1px 0"
|
||||
|
@ -17,7 +17,7 @@ import { SettingsPage } from './home/SettingsPage';
|
||||
import { MediaRoutes } from './media/MediaRoutes';
|
||||
import { OnAirPage } from './onAir/OnAirPage';
|
||||
import { SeasonRoutes } from './season/SeasonRoutes';
|
||||
import { SeriesRoutes } from './series/SeriesRoutes';
|
||||
import { SeriesRoutes } from './sso/series/SeriesRoutes';
|
||||
import { TypeRoutes } from './type/TypesRoutes';
|
||||
|
||||
export const AppRoutes = () => {
|
||||
|
@ -5,8 +5,10 @@ import { LuTrash } from 'react-icons/lu';
|
||||
import { MdCloudUpload } from 'react-icons/md';
|
||||
|
||||
import {
|
||||
Media,
|
||||
MediaResource,
|
||||
RestErrorResponse,
|
||||
Season,
|
||||
SeasonResource,
|
||||
Series,
|
||||
SeriesResource,
|
||||
Type,
|
||||
@ -22,8 +24,7 @@ import {
|
||||
NumberInputRoot,
|
||||
} from '@/components/ui/number-input';
|
||||
import { useMediaService } from '@/service/Media';
|
||||
import { useOrderedSeasons, useSeasonService } from '@/service/Season';
|
||||
import { useOrderedSeries, useSeriesService } from '@/service/Series';
|
||||
import { useOrderedSeries, useOrderedSeriesWithType, useSeriesService } from '@/service/Series';
|
||||
import { useServiceContext } from '@/service/ServiceContext';
|
||||
import { useOrderedTypes, useTypeService } from '@/service/Type';
|
||||
import { isNullOrUndefined } from '@/utils/validator';
|
||||
@ -39,14 +40,17 @@ export class ElementList {
|
||||
export class FileParsedElement {
|
||||
public isSended: boolean = false;
|
||||
public nameDetected: boolean = false;
|
||||
public MediaIdDetected: boolean = false;
|
||||
public mediaIdDetected: boolean = false;
|
||||
public seasonId?: Season['id'] = undefined;
|
||||
public seriesId?: Series['id'] = undefined;
|
||||
constructor(
|
||||
public uniqueId: number,
|
||||
public file: File,
|
||||
public title: string,
|
||||
public Series?: string,
|
||||
public Season?: string,
|
||||
public MediaId?: number
|
||||
public universe?: string,
|
||||
public series?: string,
|
||||
public season?: number,
|
||||
public mediaId?: number
|
||||
) {
|
||||
console.log(`Unique element: ${uniqueId}`);
|
||||
// nothing to do.
|
||||
@ -64,8 +68,8 @@ export class FileFailParsedElement {
|
||||
}
|
||||
|
||||
type FormInsertData = {
|
||||
TypeId?: number;
|
||||
SeriesId?: number;
|
||||
typeId?: number;
|
||||
seriesId?: number;
|
||||
titleSeason?: string;
|
||||
};
|
||||
|
||||
@ -83,11 +87,9 @@ export const AddPage = () => {
|
||||
);
|
||||
|
||||
const { dataTypes } = useOrderedTypes();
|
||||
const { dataSeries } = useOrderedSeries();
|
||||
const { dataSeasons } = useOrderedSeasons();
|
||||
const { dataSeries: dataSeriesFull } = useOrderedSeries();
|
||||
const { store: storeType } = useTypeService();
|
||||
const { store: storeSeries } = useSeriesService();
|
||||
const { store: storeSeason } = useSeasonService();
|
||||
const { store: storeMedia } = useMediaService();
|
||||
const { session } = useServiceContext();
|
||||
|
||||
@ -97,6 +99,8 @@ export const AddPage = () => {
|
||||
enableReset: false,
|
||||
},
|
||||
});
|
||||
// I think this does not work ...
|
||||
const { dataSeries } = useOrderedSeriesWithType(form.values["typeId"]);
|
||||
|
||||
const updateNeedSend = () => {
|
||||
if (parsedElement.length === 0) {
|
||||
@ -142,7 +146,12 @@ export const AddPage = () => {
|
||||
};
|
||||
|
||||
const onMediaId = (data: FileParsedElement, value: any): void => {
|
||||
data.MediaId = value;
|
||||
data.mediaId = value;
|
||||
setParsedElement([...parsedElement]);
|
||||
updateNeedSend();
|
||||
};
|
||||
const onSeasonId = (data: FileParsedElement, value: any): void => {
|
||||
data.season = value;
|
||||
setParsedElement([...parsedElement]);
|
||||
updateNeedSend();
|
||||
};
|
||||
@ -151,68 +160,64 @@ export const AddPage = () => {
|
||||
setParsedElement([]);
|
||||
setParsedFailedElement(undefined);
|
||||
setListFileInBdd(undefined);
|
||||
|
||||
setSuggestedSeries(undefined);
|
||||
setSuggestedSeason(undefined);
|
||||
//setSuggestedSeason(undefined);
|
||||
};
|
||||
|
||||
const regex = /^(?:(?<universe>[\w. -]+):)?((?<series>[\w. -]+?)((-s| S)(?<season>\d{1,5}))?(?:(-e|E)(?<episode>\d{1,5}))[- ])?\s*(?<title>.+?)\.(webm|WEBM|Webm|mkv|MKV|Mkv)$/;
|
||||
|
||||
const addFileWithMetaData = (file: File, id: number) => {
|
||||
// parsedElement: FileParsedElement[] = [];
|
||||
let Series: string | undefined = undefined;
|
||||
let Season: string | undefined = undefined;
|
||||
let MediaIdNumber: number | undefined = undefined;
|
||||
let universe: string | undefined = undefined;
|
||||
let series: string | undefined = undefined;
|
||||
let season: number | undefined = undefined;
|
||||
let mediaIdNumber: number | undefined = undefined;
|
||||
let title: string = '';
|
||||
|
||||
form.restoreValues();
|
||||
|
||||
console.log(`select file ${file.name}`);
|
||||
let tmpName = file.name.replace(/[ \t]*-[ \t]*/g, '-');
|
||||
//tmpName = tmpName.replace(/_/g, '-');
|
||||
//tmpName = tmpName.replace(/--/g, '-');
|
||||
console.log(`select file ${tmpName}`);
|
||||
const splitElement = tmpName.split('~');
|
||||
if (splitElement.length > 1) {
|
||||
Series = splitElement[0];
|
||||
tmpName = tmpName.substring(Series.length + 1);
|
||||
}
|
||||
const splitElement2 = tmpName.split('#');
|
||||
if (splitElement2.length > 1) {
|
||||
Season = splitElement2[0];
|
||||
tmpName = tmpName.substring(Season.length + 1);
|
||||
}
|
||||
//console.log("ploppppp " + tmpName);
|
||||
const splitElement3 = tmpName.split('-');
|
||||
if (splitElement3.length > 1) {
|
||||
MediaIdNumber = parseInt(splitElement3[0], 10);
|
||||
tmpName = tmpName.substring(splitElement3[0].length + 1);
|
||||
}
|
||||
//console.log("KKKppppp " + tmpName);
|
||||
//console.log(" ===> " + splitElement3[0]);
|
||||
title = tmpName;
|
||||
|
||||
if (MediaIdNumber && isNaN(MediaIdNumber)) {
|
||||
MediaIdNumber = undefined;
|
||||
const match = file.name.match(regex);
|
||||
if (match?.groups) {
|
||||
universe = match.groups.universe || undefined;
|
||||
series = match.groups.series ? match.groups.series.trim() : undefined;
|
||||
season = match.groups.season? parseInt(match.groups.season, 10) : undefined;
|
||||
mediaIdNumber = match.groups.episode ? parseInt(match.groups.episode, 10) : undefined;
|
||||
title = match.groups.title.trim();
|
||||
} else {
|
||||
console.log("❌ not match :", file.name);
|
||||
title = file.name.trim();
|
||||
}
|
||||
|
||||
if (season && isNaN(season)) {
|
||||
season = undefined;
|
||||
}
|
||||
if (mediaIdNumber && isNaN(mediaIdNumber)) {
|
||||
mediaIdNumber = undefined;
|
||||
}
|
||||
// remove extension
|
||||
title = title.replace(new RegExp('\\.(webm|WEBM|Webm)'), '');
|
||||
title = title.replace(new RegExp('\\.(webm|WEBM|Webm|mkv|MKV|Mkv)'), '');
|
||||
let tmp = new FileParsedElement(
|
||||
id,
|
||||
file,
|
||||
title,
|
||||
Series,
|
||||
Season,
|
||||
MediaIdNumber
|
||||
universe,
|
||||
series,
|
||||
season,
|
||||
mediaIdNumber
|
||||
);
|
||||
console.log(`==>${JSON.stringify(tmp)}`);
|
||||
console.log(`==>${JSON.stringify(tmp, null, 2)}`);
|
||||
|
||||
// add it in the list.
|
||||
return tmp;
|
||||
};
|
||||
const [suggestedSeries, setSuggestedSeries] = useState<string | undefined>(
|
||||
undefined
|
||||
);
|
||||
const [suggestedSeason, setSuggestedSeason] = useState<string | undefined>(
|
||||
undefined
|
||||
);
|
||||
// const [suggestedSeason, setSuggestedSeason] = useState<string | undefined>(
|
||||
// undefined
|
||||
// );
|
||||
|
||||
const onChangeFile = (value: any): void => {
|
||||
clearData();
|
||||
@ -232,9 +237,9 @@ export const AddPage = () => {
|
||||
// clean different Series:
|
||||
for (let iii = 1; iii < parsedElementTmp.length; iii++) {
|
||||
console.log(
|
||||
`check Series [${iii + 1}/${parsedElementTmp.length}] '${parsedElementTmp[0].Series} !== ${parsedElementTmp[iii].Series}'`
|
||||
`check Series [${iii + 1}/${parsedElementTmp.length}] '${parsedElementTmp[0].series} !== ${parsedElementTmp[iii].series}'`
|
||||
);
|
||||
if (parsedElementTmp[0].Series !== parsedElementTmp[iii].Series) {
|
||||
if (parsedElementTmp[0].series !== parsedElementTmp[iii].series) {
|
||||
parsedFailedElementTmp.push(
|
||||
new FileFailParsedElement(
|
||||
parsedFailedElementTmp.length,
|
||||
@ -249,64 +254,29 @@ export const AddPage = () => {
|
||||
iii--;
|
||||
}
|
||||
}
|
||||
// clean different Season:
|
||||
for (let iii = 1; iii < parsedElementTmp.length; iii++) {
|
||||
console.log(
|
||||
`check Season [${iii + 1}/${parsedElementTmp.length}] '${parsedElementTmp[0].Season} !== ${parsedElementTmp[iii].Season}'`
|
||||
);
|
||||
if (parsedElementTmp[0].Season !== parsedElementTmp[iii].Season) {
|
||||
parsedFailedElementTmp.push(
|
||||
new FileFailParsedElement(
|
||||
parsedFailedElementTmp.length,
|
||||
parsedElementTmp[iii].file,
|
||||
'Remove from list due to wrong Season value'
|
||||
)
|
||||
);
|
||||
console.log(
|
||||
`Remove from list (!= Season) : [${iii + 1}/${parsedElementTmp.length}] '${parsedElementTmp[iii].file.name}'`
|
||||
);
|
||||
parsedElementTmp.splice(iii, 1);
|
||||
iii--;
|
||||
}
|
||||
}
|
||||
setParsedElement(parsedElementTmp);
|
||||
setParsedFailedElement(parsedFailedElementTmp);
|
||||
console.log(`check : ${JSON.stringify(parsedElementTmp[0])}`);
|
||||
|
||||
// find SeriesId:
|
||||
console.log(`try find Series : ${parsedElementTmp[0].Series}`);
|
||||
// find seriesId:
|
||||
console.log(`try find Series : ${parsedElementTmp[0].series}`);
|
||||
let SeriesFound = false;
|
||||
dataSeries.forEach((data) => {
|
||||
dataSeriesFull.forEach((data) => {
|
||||
if (
|
||||
data.name?.toLowerCase() === parsedElementTmp[0].Series?.toLowerCase()
|
||||
data.name?.toLowerCase() === parsedElementTmp[0].series?.toLowerCase()
|
||||
) {
|
||||
console.log(` find Series : ${data.id}`);
|
||||
form.setValues({ SeriesId: data.id });
|
||||
form.setValues({ seriesId: data.id });
|
||||
form.setValues({ typeId: data.parentId });
|
||||
SeriesFound = true;
|
||||
}
|
||||
});
|
||||
if (!SeriesFound) {
|
||||
console.log(` set Suggested Series : ${parsedElementTmp[0].Series}`);
|
||||
setSuggestedSeries(parsedElementTmp[0].Series);
|
||||
console.log(` set Suggested Series : ${parsedElementTmp[0].series}`);
|
||||
setSuggestedSeries(parsedElementTmp[0].series);
|
||||
} else {
|
||||
setSuggestedSeries(undefined);
|
||||
}
|
||||
// try to find Season
|
||||
console.log(`try find Season : ${parsedElementTmp[0].Season}`);
|
||||
let SeasonFound = false;
|
||||
dataSeasons.forEach((data) => {
|
||||
if (
|
||||
data.name?.toLowerCase() === parsedElementTmp[0].Season?.toLowerCase()
|
||||
) {
|
||||
console.log(` find Season : ${data.id}`);
|
||||
form.setValues({ SeasonId: data.id });
|
||||
SeasonFound = true;
|
||||
}
|
||||
});
|
||||
if (!SeasonFound) {
|
||||
console.log(` set Suggested Season : ${parsedElementTmp[0].Season}`);
|
||||
setSuggestedSeason(parsedElementTmp[0].Season);
|
||||
}
|
||||
updateNeedSend();
|
||||
};
|
||||
|
||||
@ -327,6 +297,9 @@ export const AddPage = () => {
|
||||
|
||||
const uploadNext = useCallback(
|
||||
(index: number = 0): void => {
|
||||
// if (indexUpload == undefined) {
|
||||
// return;
|
||||
// }
|
||||
if (parsedElement.length <= index) {
|
||||
console.log('end of upload');
|
||||
setIsFinishedUpload(true);
|
||||
@ -339,33 +312,34 @@ export const AddPage = () => {
|
||||
const data = {
|
||||
title: parsedElement[index].title,
|
||||
file: parsedElement[index].file,
|
||||
SeasonId: form.values['SeasonId'] ?? undefined,
|
||||
SeriesId: form.values['SeriesId'] ?? undefined,
|
||||
TypeId: form.values['TypeId'] ?? undefined,
|
||||
MediaId: parsedElement[index].MediaId ?? undefined,
|
||||
universeId: `${form.values['universeId']}`,
|
||||
typeId: `${form.values['typeId']}`,
|
||||
seriesId: `${form.values['seriesId']}`,
|
||||
season: `${parsedElement[index].season}`,
|
||||
episode: `${parsedElement[index].mediaId}`,
|
||||
};
|
||||
console.log(`data= ${JSON.stringify(data, null, 2)}`);
|
||||
console.error("Not_ implemented");
|
||||
// storeMedia
|
||||
// .update(
|
||||
// MediaResource.uploadMedia({
|
||||
// restConfig: session.getRestConfig(),
|
||||
// data,
|
||||
// callbacks: {
|
||||
// progressUpload: progressUpload,
|
||||
// },
|
||||
// })
|
||||
// )
|
||||
// .then((data: Media) => {
|
||||
// // element sended good
|
||||
// // Send next ...
|
||||
// uploadNext(index + 1);
|
||||
// })
|
||||
// .catch((error: RestErrorResponse) => {
|
||||
// // TODO: manage error
|
||||
// console.log(`element error: ${JSON.stringify(error, null, 2)}`);
|
||||
// setUploadError(JSON.stringify(error, null, 2));
|
||||
// });
|
||||
storeMedia
|
||||
.update(
|
||||
MediaResource.uploadMedia({
|
||||
restConfig: session.getRestConfig(),
|
||||
data,
|
||||
callbacks: {
|
||||
progressUpload: progressUpload,
|
||||
},
|
||||
})
|
||||
)
|
||||
.then((data: Media) => {
|
||||
// element sended good
|
||||
// Send next ...
|
||||
uploadNext(index + 1);
|
||||
})
|
||||
.catch((error: RestErrorResponse) => {
|
||||
// TODO: manage error
|
||||
console.log(`element error: ${JSON.stringify(error, null, 2)}`);
|
||||
setUploadError(JSON.stringify(error, null, 2));
|
||||
});
|
||||
},
|
||||
[
|
||||
setUploadError,
|
||||
@ -374,6 +348,7 @@ export const AddPage = () => {
|
||||
parsedElement,
|
||||
form,
|
||||
form.values,
|
||||
indexUpload,
|
||||
]
|
||||
);
|
||||
|
||||
@ -409,16 +384,7 @@ export const AddPage = () => {
|
||||
restConfig: session.getRestConfig(),
|
||||
data: {
|
||||
name: data,
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
const addNewSeason = (data: string): Promise<Season> => {
|
||||
return storeSeason.update(
|
||||
SeasonResource.post({
|
||||
restConfig: session.getRestConfig(),
|
||||
data: {
|
||||
name: data,
|
||||
parentId: form.values["typeId"]
|
||||
},
|
||||
})
|
||||
);
|
||||
@ -439,11 +405,10 @@ export const AddPage = () => {
|
||||
<Flex>
|
||||
<Text flex={1}>format:</Text>
|
||||
<Text flex={4}>
|
||||
The format of the media permit to automatic find meta-data:
|
||||
<br />
|
||||
Series~Season#idMedia-my name of my media.webm
|
||||
<br />
|
||||
<b>example:</b> Clarika~Moi En Mieux#22-des bulles.webm
|
||||
The format of the media permit to automatic find meta-data:<br />
|
||||
<li>Universe:Series name-s05-e22-Title.webm/mkv</li>
|
||||
<li>Universe:Series name S05E22 Title.webm/mkv</li>
|
||||
<b>example:</b> Stargate:SG1-s05-e22-Tolans.webm
|
||||
</Text>
|
||||
</Flex>
|
||||
<Flex>
|
||||
@ -452,7 +417,7 @@ export const AddPage = () => {
|
||||
flex={4}
|
||||
type="file"
|
||||
placeholder="Select a media file"
|
||||
accept=".webm"
|
||||
accept=".webm,.mkv"
|
||||
multiple
|
||||
onChange={onChangeFile}
|
||||
/>
|
||||
@ -463,24 +428,20 @@ export const AddPage = () => {
|
||||
<Text fontSize="30px">Meta-data:</Text>
|
||||
<FormSelect
|
||||
label="Type"
|
||||
name="TypeId"
|
||||
name="typeId"
|
||||
options={dataTypes}
|
||||
addNewItem={addNewType}
|
||||
isRequired
|
||||
/>
|
||||
<FormSelect
|
||||
label="Series"
|
||||
name="SeriesId"
|
||||
name="seriesId"
|
||||
options={dataSeries}
|
||||
addNewItem={addNewSeries}
|
||||
suggestion={suggestedSeries}
|
||||
disabled={form.values["typeId"] === undefined}
|
||||
/>
|
||||
<FormSelect
|
||||
label="Season"
|
||||
name="SeasonId"
|
||||
options={dataSeasons}
|
||||
addNewItem={addNewSeason}
|
||||
suggestion={suggestedSeason}
|
||||
/>
|
||||
|
||||
<Table.Root
|
||||
colorPalette="striped"
|
||||
colorScheme="teal"
|
||||
@ -488,6 +449,9 @@ export const AddPage = () => {
|
||||
>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.ColumnHeader width="10%">
|
||||
Season ID
|
||||
</Table.ColumnHeader>
|
||||
<Table.ColumnHeader width="10%">
|
||||
Media ID
|
||||
</Table.ColumnHeader>
|
||||
@ -499,19 +463,38 @@ export const AddPage = () => {
|
||||
{parsedElement.map((data) => (
|
||||
<Table.Row key={data.uniqueId}>
|
||||
<Table.Cell>
|
||||
{form.values["seriesId"] &&
|
||||
<NumberInputRoot
|
||||
value={data.MediaId ? `${data.MediaId}` : undefined}
|
||||
onValueChange={(e) => onMediaId(data, e.value)}
|
||||
value={data.season ? `${data.season}` : undefined}
|
||||
onValueChange={(e) => onSeasonId(data, e.value)}
|
||||
min={0}
|
||||
max={5000}
|
||||
backgroundColor={
|
||||
data.MediaIdDetected === true
|
||||
data.mediaIdDetected === true
|
||||
? 'darkred'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<NumberInputField />
|
||||
</NumberInputRoot>
|
||||
}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{form.values["seriesId"] &&
|
||||
<NumberInputRoot
|
||||
value={data.mediaId ? `${data.mediaId}` : undefined}
|
||||
onValueChange={(e) => onMediaId(data, e.value)}
|
||||
min={0}
|
||||
max={5000}
|
||||
backgroundColor={
|
||||
data.mediaIdDetected === true
|
||||
? 'darkred'
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<NumberInputField />
|
||||
</NumberInputRoot>
|
||||
}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
<Input
|
||||
|
@ -45,8 +45,8 @@ export const TypesPage = () => {
|
||||
{dataTypes.map((data) => (
|
||||
<Flex
|
||||
align="flex-start"
|
||||
width={{ base: "200px", sm: "160px" }}
|
||||
height={{ base: "280px", sm: "200px" }}
|
||||
width={{ lg: "200px", base: "160px" }}
|
||||
height={{ lg: "280px", base: "200px" }}
|
||||
border="1px"
|
||||
borderColor="brand.900"
|
||||
backgroundColor={useColorModeValue('#FFFFFF88', '#00000088')}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { Series, SeriesResource } from '@/back-api';
|
||||
import { Series, SeriesResource, Type } from '@/back-api';
|
||||
import { useServiceContext } from '@/service/ServiceContext';
|
||||
import { SessionServiceProps } from '@/service/session';
|
||||
import { DataStoreType, useDataStore } from '@/utils/data-store';
|
||||
@ -60,6 +60,35 @@ export const useOrderedSeries = (nameFilter?: string) => {
|
||||
}, [store.data, nameFilter]);
|
||||
return { isLoading: store.isLoading, dataSeries };
|
||||
};
|
||||
export const useOrderedSeriesWithType = (typeId?: Type["id"], nameFilter?: string) => {
|
||||
const { store } = useSeriesService();
|
||||
const dataSeries = useMemo(() => {
|
||||
let tmpData = store.data;
|
||||
if (!isNullOrUndefined(nameFilter)) {
|
||||
tmpData = DataTools.getNameLike(tmpData, nameFilter);
|
||||
}
|
||||
if (typeId === undefined) {
|
||||
return [];
|
||||
}
|
||||
return DataTools.getsWhere(
|
||||
tmpData,
|
||||
[
|
||||
{
|
||||
check: TypeCheck.NOT_EQUAL,
|
||||
key: 'id',
|
||||
value: [undefined, null],
|
||||
},
|
||||
{
|
||||
check: TypeCheck.EQUAL,
|
||||
key: 'parentId',
|
||||
value: typeId,
|
||||
},
|
||||
],
|
||||
['name', 'id']
|
||||
);
|
||||
}, [store.data, nameFilter, typeId]);
|
||||
return { isLoading: store.isLoading, dataSeries };
|
||||
};
|
||||
|
||||
export const useSpecificSeries = (id: number | undefined) => {
|
||||
const { store } = useSeriesService();
|
||||
|
@ -102,6 +102,9 @@ export const ServiceContext = createContext<ServiceContextType>({
|
||||
first: () => {
|
||||
console.error('!!! WTF !!!');
|
||||
},
|
||||
clear: () => {
|
||||
console.error('!!! WTF !!!');
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user