-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement sharing of document through netlify blobs (#1135)
- Loading branch information
1 parent
9833c64
commit 1608159
Showing
15 changed files
with
348 additions
and
126 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
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 @@ | ||
[devs] | ||
functions = "apps/studio-next/src/netlify/functions" | ||
targetPort = 3001 | ||
|
||
[build] | ||
functions = "apps/studio-next/src/netlify/functions" |
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
57 changes: 57 additions & 0 deletions
57
apps/studio-next/src/components/Modals/ImportUUIDModal.tsx
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,57 @@ | ||
import { useState } from 'react'; | ||
import toast from 'react-hot-toast'; | ||
import { create } from '@ebay/nice-modal-react'; | ||
|
||
import { ConfirmModal } from './index'; | ||
|
||
import { useServices } from '../../services'; | ||
|
||
export const ImportUUIDModal = create(() => { | ||
const [shareID, setShareID] = useState(''); | ||
const { editorSvc } = useServices(); | ||
|
||
const onSubmit = () => { | ||
toast.promise(editorSvc.importFromShareID(shareID), { | ||
loading: 'Importing...', | ||
success: ( | ||
<div> | ||
<span className="block text-bold"> | ||
Document succesfully imported! | ||
</span> | ||
</div> | ||
), | ||
error: ( | ||
<div> | ||
<span className="block text-bold text-red-400"> | ||
Failed to import document. | ||
</span> | ||
</div> | ||
), | ||
}); | ||
}; | ||
|
||
return ( | ||
<ConfirmModal | ||
title="Import AsyncAPI document from Shared UUID" | ||
confirmText="Import" | ||
confirmDisabled={!shareID} | ||
onSubmit={onSubmit} | ||
> | ||
<div className="flex content-center justify-center"> | ||
<label | ||
htmlFor="url" | ||
className="flex justify-right items-center content-center text-sm font-medium text-gray-700 hidden" | ||
> | ||
Shared UUID | ||
</label> | ||
<input | ||
type="url" | ||
name="url" | ||
placeholder="Paste UUID here" | ||
className="shadow-sm focus:ring-pink-500 focus:border-pink-500 block w-full sm:text-sm border-gray-300 rounded-md py-2 px-3 text-gray-700 border-pink-300 border-2" | ||
onChange={e => setShareID(e.target.value)} | ||
/> | ||
</div> | ||
</ConfirmModal> | ||
); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getStore } from '@netlify/blobs'; | ||
import type { Config, Context } from '@netlify/functions'; | ||
|
||
export default async (req: Request, context: Context) => { | ||
const share = getStore('share'); | ||
const { shareId } = context.params; | ||
|
||
if (!shareId) { | ||
return new Response('Not found', { status: 404 }); | ||
} | ||
|
||
const shareData = await share.get(shareId); | ||
|
||
if (!shareData) { | ||
return new Response('Not found', { status: 404 }); | ||
} | ||
|
||
return new Response(shareData, { | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
} | ||
|
||
export const config: Config = { | ||
path: '/share/:shareId', | ||
}; |
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,26 @@ | ||
import { getStore } from '@netlify/blobs'; | ||
import type { Config, Context } from '@netlify/functions'; | ||
import { randomUUID } from 'crypto'; | ||
|
||
export default async (req: Request, context: Context) => { | ||
const share = getStore('share'); | ||
const shareId = randomUUID(); | ||
|
||
const state = await req.json(); | ||
|
||
await share.set(shareId, JSON.stringify({ | ||
URL: `${context.site.url }?share=${ shareId}`, | ||
...state, | ||
created: Date.now(), | ||
})) | ||
|
||
return new Response(shareId, { | ||
headers: { | ||
'content-type': 'text/plain', | ||
}, | ||
}); | ||
}; | ||
|
||
export const config: Config = { | ||
path: '/share', | ||
} |
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.