-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
feat: implement sharing of document through netlify blobs #1135
Merged
+348
−126
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6aa9188
feat: implement basic netlify function utilising blobs for sharing
Shurtu-gal 1b02833
chore: pivot from edge functions to normal ones
Shurtu-gal 156c5e9
feat: add share functionality to website
Shurtu-gal c276af6
chore: add from shared to subtitle
Shurtu-gal 44f0c77
Merge remote-tracking branch 'upstream/master' into share-feature
Shurtu-gal 4c17ed0
chore: apply requested changes
Shurtu-gal 14a7923
chore: styling issues
Shurtu-gal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that we've used this library without an ADR, It's fine.
Could we just add an ADR for it, to understand the reasoning behind it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, let me check in which commit it was introduced initially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Amzani it was introduced in this PR #518.
Should an ADR still be made?