Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 fix: flydrive adapter #197

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const { adapter, handler } = initOberon({
```typescript
// config.ts
import { Image } from "@oberoncms/plugin-flydrive" // <- import the Image component
import ImageNestedField from "@oberoncms/plugin-flydrive/field" // <- import the nested field
export const editorConfig = {
// other configurations
Expand All @@ -91,7 +90,7 @@ export const editorConfig = {
images: {
type: "array",
arrayFields: {
image: ImageNestedField,
image: Image.fields.image
// another array fields
},
},
Expand All @@ -100,7 +99,7 @@ export const editorConfig = {
image: {
type: "object",
objectFields: {
image: ImageNestedField ,
image: Image.fields.image ,
// another object fields
},
},
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/flydrive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"node": "./dist/server.js"
},
"./vercel": "./dist/extentions/vercel.js",
"./field": "./dist/blocks/field.js",
"./plugin": "./dist/plugin.js"
},
"files": [
Expand Down
3 changes: 0 additions & 3 deletions packages/plugins/flydrive/src/blocks/field.ts

This file was deleted.

12 changes: 10 additions & 2 deletions packages/plugins/flydrive/src/internal/disk-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import { randomUUID } from "crypto"
import path from "path"
import { NextRequest } from "next/server"
import type { Disk } from "flydrive"
import { OberonAdapter, OberonError, ResponseError } from "@oberoncms/core"
import { getImageSize } from "./get-image-size"

export function initRouteHandler(disk: Disk): {
export function initRouteHandler(
{ can }: OberonAdapter,
disk: Disk,
): {
POST: (req: NextRequest) => Promise<Response>
GET: (req: NextRequest) => Promise<Response>
} {
const POST: (req: NextRequest) => Promise<Response> = async (req) => {
if (!(await can("images", "write"))) {
throw new ResponseError("Not Allowed")
}

const image = (await req.formData()).get("image") as File | null
if (!image) {
return new Response("No image provided", { status: 400 })
throw new OberonError("No image provided")
}

const toBuffer = await image.arrayBuffer()
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/flydrive/src/internal/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const getFlyDrivePlugin = (diskDriver: DriverContract): OberonPlugin => {
name,
version,
handlers: {
flydrive: () => initRouteHandler(driver),
flydrive: (adapter) => initRouteHandler(adapter, driver),
},
adapter: {
deleteImage: async (key) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/flydrive/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { initConfig } from "@tohuhono/dev/vite.config"

export default initConfig()
export default initConfig(["src/*.{ts,tsx}", "src/**/*.{ts,tsx}"])