Skip to content

Commit

Permalink
πŸ”¨ fix: flydrive adapter (#197)
Browse files Browse the repository at this point in the history
* πŸ”¨ fix: flydrive adapter

* πŸ”¨ fix: extention build js files
  • Loading branch information
ahmedrowaihi authored Jun 28, 2024
1 parent b6d32fa commit f00476f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
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}"])

0 comments on commit f00476f

Please sign in to comment.