Skip to content

Commit 68a65be

Browse files
Maximilian Zinketommoor
Maximilian Zinke
andauthored
feat: Embed Google Drive (outline#1804)
* implement google drive extension * add current logo of google drive * fix issue when posting gdrive links which are already a preview * always only show the preview * Add bottom bar to get to original url for Google Drive embeds Co-authored-by: Tom Moor <tom.moor@gmail.com>
1 parent b4d307b commit 68a65be

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

app/embeds/GoogleDrive.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @flow
2+
import * as React from "react";
3+
import Frame from "./components/Frame";
4+
5+
const URL_REGEX = new RegExp(
6+
"^https?://drive.google.com/file/d/(.*)/(preview|view).?usp=sharing$"
7+
);
8+
9+
type Props = {|
10+
attrs: {|
11+
href: string,
12+
matches: string[],
13+
|},
14+
|};
15+
16+
export default class GoogleDrive extends React.Component<Props> {
17+
static ENABLED = [URL_REGEX];
18+
19+
render() {
20+
return (
21+
<Frame
22+
src={this.props.attrs.href.replace("/view", "/preview")}
23+
icon={
24+
<img
25+
src="/images/google-drive.png"
26+
alt="Google Drive Icon"
27+
width={16}
28+
height={16}
29+
/>
30+
}
31+
title="Google Drive Embed"
32+
canonicalUrl={this.props.attrs.href}
33+
border
34+
/>
35+
);
36+
}
37+
}

app/embeds/GoogleDrive.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* eslint-disable flowtype/require-valid-file-annotation */
2+
import GoogleDrive from "./GoogleDrive";
3+
4+
describe("GoogleDrive", () => {
5+
const match = GoogleDrive.ENABLED[0];
6+
test("to be enabled on share link", () => {
7+
expect(
8+
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=sharing".match(
9+
match
10+
)
11+
).toBeTruthy();
12+
expect(
13+
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/preview?usp=sharing".match(
14+
match
15+
)
16+
).toBeTruthy();
17+
});
18+
19+
test("to not be enabled elsewhere", () => {
20+
expect(
21+
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view".match(
22+
match
23+
)
24+
).toBe(null);
25+
expect(
26+
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/preview".match(
27+
match
28+
)
29+
).toBe(null);
30+
expect(
31+
"https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=restricted".match(
32+
match
33+
)
34+
).toBeTruthy();
35+
expect("https://drive.google.com/file".match(match)).toBe(null);
36+
expect("https://drive.google.com".match(match)).toBe(null);
37+
expect("https://www.google.com".match(match)).toBe(null);
38+
});
39+
});

app/embeds/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Codepen from "./Codepen";
88
import Figma from "./Figma";
99
import Framer from "./Framer";
1010
import Gist from "./Gist";
11+
import GoogleDrive from "./GoogleDrive";
1112
import GoogleDocs from "./GoogleDocs";
1213
import GoogleSheets from "./GoogleSheets";
1314
import GoogleSlides from "./GoogleSlides";
@@ -93,6 +94,13 @@ export default [
9394
component: Gist,
9495
matcher: matcher(Gist),
9596
},
97+
{
98+
title: "Google Drive",
99+
keywords: "drive",
100+
icon: () => <Img src="/images/google-drive.png" />,
101+
component: GoogleDrive,
102+
matcher: matcher(GoogleDrive),
103+
},
96104
{
97105
title: "Google Docs",
98106
icon: () => <Img src="/images/google-docs.png" />,

public/images/google-drive.png

9.12 KB
Loading

0 commit comments

Comments
 (0)