forked from misskey-dev/summaly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
44 additions
and
141 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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,31 +1,24 @@ | ||
import * as URL from 'url'; | ||
import ISummary from './isummary'; | ||
import IPlugin from './iplugin'; | ||
import Options from './options'; | ||
import general from './general'; | ||
|
||
// Init babel | ||
require('babel-core/register'); | ||
require('babel-polyfill'); | ||
|
||
const plugins: IPlugin[] = [ | ||
require('./plugins/wikipedia'), | ||
require('./plugins/soundcloud'), | ||
require('./plugins/youtube') | ||
require('./plugins/wikipedia') | ||
]; | ||
|
||
export default async (url: string, options?: Options): Promise<string> => { | ||
export default async (url: string): Promise<ISummary> => { | ||
const _url = URL.parse(url, true); | ||
|
||
const opts: any = options || {}; | ||
if (!opts.hasOwnProperty('proxy')) { | ||
opts.proxy = null; | ||
} | ||
|
||
const plugin = plugins.filter(plugin => plugin.test(_url))[0]; | ||
|
||
if (plugin) { | ||
return await plugin.compile(_url, opts); | ||
return await plugin.summary(_url); | ||
} else { | ||
return await general(_url, opts); | ||
return await general(_url); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import * as URL from 'url'; | ||
import Options from './options'; | ||
import ISummary from './isummary'; | ||
|
||
interface IPlugin { | ||
test: (url: URL.Url) => boolean; | ||
compile: (url: URL.Url, opts: Options) => Promise<string>; | ||
summary: (url: URL.Url) => Promise<ISummary>; | ||
} | ||
|
||
export default IPlugin; | ||
export default IPlugin; |
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,9 @@ | ||
interface ISummary { | ||
title: string; | ||
icon: string; | ||
description: string; | ||
thumbnail: string; | ||
sitename: string; | ||
} | ||
|
||
export default ISummary; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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