-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from vevcom/chore/remove-image-ntnu-from-src
Chore/Licenses
- Loading branch information
Showing
72 changed files
with
897 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,7 @@ | ||
'use server' | ||
import { safeServerCall } from '@/actions/safeServerCall' | ||
import { createZodActionError } from '@/actions/error' | ||
import { createImage } from '@/services/images/create' | ||
import { createImagesValidation, createImageValidation } from '@/services/images/validation' | ||
import type { ActionReturn } from '@/actions/Types' | ||
import type { Image } from '@prisma/client' | ||
import type { CreateImageTypes, CreateImagesTypes } from '@/services/images/validation' | ||
import { Action } from '@/actions/Action' | ||
import { Images } from '@/services/images' | ||
|
||
export async function createImageAction( | ||
collectionId: number, | ||
rawdata: FormData | CreateImageTypes['Type'] | ||
): Promise<ActionReturn<Image>> { | ||
//TODO: add auth | ||
export const createImageAction = Action(Images.create) | ||
|
||
const parse = createImageValidation.typeValidate(rawdata) | ||
if (!parse.success) return createZodActionError(parse) | ||
const data = parse.data | ||
|
||
return await safeServerCall(() => createImage({ ...data, collectionId })) | ||
} | ||
|
||
export async function createImagesAction( | ||
useFileName: boolean, | ||
collectionId: number, | ||
rawdata: FormData | CreateImagesTypes['Type'] | ||
): Promise<ActionReturn<void>> { | ||
//TODO: add auth | ||
|
||
const parse = createImagesValidation.typeValidate(rawdata) | ||
|
||
if (!parse.success) return createZodActionError(parse) | ||
|
||
const data = parse.data | ||
|
||
let finalReturn: ActionReturn<void> = { success: true, data: undefined } | ||
for (const file of data.files) { | ||
const name = useFileName ? file.name.split('.')[0] : undefined | ||
const ret = await safeServerCall( | ||
() => createImage({ file, name, alt: file.name.split('.')[0], collectionId }) | ||
) | ||
if (!ret.success) return ret | ||
finalReturn = { | ||
...finalReturn, | ||
success: ret.success, | ||
} | ||
} | ||
return finalReturn | ||
} | ||
export const createImagesAction = Action(Images.createMany) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,19 @@ | ||
'use server' | ||
import { safeServerCall } from '@/actions/safeServerCall' | ||
import { createActionError } from '@/actions/error' | ||
import { readImage, readImagesPage, readSpecialImage } from '@/services/images/read' | ||
import { createBadImage } from '@/services/images/create' | ||
import { SpecialImage } from '@prisma/client' | ||
import type { Image } from '@prisma/client' | ||
import type { ReadPageInput } from '@/lib/paging/Types' | ||
import type { ActionReturn } from '@/actions/Types' | ||
import type { ImageDetails, ImageCursor } from '@/services/images/Types' | ||
import { ActionNoData } from '@/actions/Action' | ||
import { Images } from '@/services/images' | ||
|
||
|
||
/** | ||
* Read one page of images. | ||
* @param pageReadInput - the page with details and page. | ||
* @returns | ||
*/ | ||
export async function readImagesPageAction<const PageSize extends number>( | ||
pageReadInput: ReadPageInput<PageSize, ImageCursor, ImageDetails> | ||
): Promise<ActionReturn<Image[]>> { | ||
//TODO: auth route based on collection | ||
return await safeServerCall(() => readImagesPage(pageReadInput)) | ||
} | ||
export const readImagesPageAction = ActionNoData(Images.readPage) | ||
|
||
/** | ||
* Read one image. | ||
* @param nameOrId - the name or id of the image to read | ||
* @returns | ||
*/ | ||
export async function readImageAction(id: number): Promise<ActionReturn<Image>> { | ||
//TODO: auth route based on collection | ||
return await safeServerCall(() => readImage(id)) | ||
} | ||
*/ | ||
export const readImageAction = ActionNoData(Images.read) | ||
|
||
/** | ||
* Action that reads a "special" image - read on this in the docs. If it does not exist it will create it, but | ||
* its conntent will not be the intended content. This is NOT under any circomstainses supposed to happen | ||
* @param special - the special image to read | ||
* @returns the special image | ||
* Read one special image. | ||
*/ | ||
export async function readSpecialImageAction(special: SpecialImage): Promise<ActionReturn<Image>> { | ||
if (!Object.values(SpecialImage).includes(special)) { | ||
return createActionError('BAD PARAMETERS', `${special} is not special`) | ||
} | ||
//TODO: auth image based on collection | ||
const imageRes = await safeServerCall(() => readSpecialImage(special)) | ||
if (!imageRes.success) { | ||
if (imageRes.errorCode === 'NOT FOUND') { | ||
return await safeServerCall(() => createBadImage(special, { | ||
special, | ||
})) | ||
} | ||
return imageRes | ||
} | ||
const image = imageRes.data | ||
return { success: true, data: image } | ||
} | ||
export const readSpecialImageAction = ActionNoData(Images.readSpecial) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
import { Action } from '@/actions/Action' | ||
import { Licenses } from '@/services/licenses' | ||
|
||
export const createLicenseAction = Action(Licenses.create) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
import { ActionNoData } from '@/actions/Action' | ||
import { Licenses } from '@/services/licenses' | ||
|
||
export const destroyLicenseAction = ActionNoData(Licenses.destroy) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use server' | ||
|
||
import { ActionNoData } from '@/actions/Action' | ||
import { Licenses } from '@/services/licenses' | ||
|
||
|
||
export const readLicensesAction = ActionNoData(Licenses.readAll) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
'use server' | ||
|
||
import { Licenses } from '@/services/licenses' | ||
import { Action } from '@/actions/Action' | ||
|
||
export const updateLicenseAction = Action(Licenses.update) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,8 @@ | |
} | ||
} | ||
} | ||
} | ||
.submitButton { | ||
margin: 0; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.