Merge embed service with backend

This commit is contained in:
Robert Schäfer 2019-07-19 20:32:53 +02:00
parent b3712d9e11
commit d4c3b7ac10
18 changed files with 791 additions and 4222 deletions

View File

@ -58,6 +58,7 @@
"dotenv": "~8.0.0",
"express": "^4.17.1",
"faker": "Marak/faker.js#master",
"got": "^9.6.0",
"graphql": "~14.4.2",
"graphql-custom-directives": "~0.2.14",
"graphql-iso-date": "~3.6.1",
@ -69,6 +70,23 @@
"linkifyjs": "~2.1.8",
"lodash": "~4.17.14",
"merge-graphql-schemas": "^1.5.8",
"metascraper": "^4.10.3",
"metascraper-audio": "^5.5.0",
"metascraper-author": "^4.8.5",
"metascraper-clearbit-logo": "^5.3.0",
"metascraper-date": "^4.8.5",
"metascraper-description": "^5.5.0",
"metascraper-image": "^4.8.5",
"metascraper-lang": "^4.8.5",
"metascraper-lang-detector": "^4.8.5",
"metascraper-logo": "^5.5.0",
"metascraper-logo-favicon": "^4.8.5",
"metascraper-publisher": "^4.8.5",
"metascraper-soundcloud": "^5.5.3",
"metascraper-title": "^4.8.5",
"metascraper-url": "^5.5.0",
"metascraper-video": "^4.8.5",
"metascraper-youtube": "^4.8.5",
"neo4j-driver": "~1.7.4",
"neo4j-graphql-js": "^2.6.3",
"neode": "^0.2.16",
@ -76,6 +94,7 @@
"nodemailer": "^6.3.0",
"npm-run-all": "~4.1.5",
"request": "~2.88.0",
"request-promise-native": "^1.0.5",
"sanitize-html": "~1.20.1",
"slug": "~1.1.0",
"trunc-html": "~1.1.2",

View File

@ -136,6 +136,7 @@ const permissions = shield(
Query: {
'*': deny,
findPosts: allow,
embed: allow,
Category: allow,
Tag: allow,
Report: isModerator,

View File

@ -0,0 +1,9 @@
import scraper from './embeds/scraper.js'
export default {
Query: {
embed: async (object, {url} , context, resolveInfo) => {
return await scraper.fetch(url)
}
}
}

View File

@ -1,4 +1,18 @@
const metascraper = require('metascraper')([
import Metascraper from 'metascraper'
import { ApolloError } from 'apollo-server'
import parseUrl from 'url'
import got from 'got'
import request from 'request-promise-native'
import find from 'lodash/find'
import isEmpty from 'lodash/isEmpty'
import each from 'lodash/each'
import isArray from 'lodash/isArray'
import mergeWith from 'lodash/mergeWith'
import urlParser from 'url'
const metascraper = Metascraper ([
require('metascraper-author')(),
require('metascraper-date')(),
require('metascraper-description')(),
@ -18,17 +32,7 @@ const metascraper = require('metascraper')([
// require('./rules/metascraper-embed')()
])
const { ApolloError } = require('apollo-server')
const parseUrl = require('url')
const got = require('got')
const request = require('request-promise-native')
const find = require('lodash/find')
const isEmpty = require('lodash/isEmpty')
const each = require('lodash/each')
const isArray = require('lodash/isArray')
const mergeWith = require('lodash/mergeWith')
const urlParser = require('url')
// quick in memory cache
let cache = {}

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +0,0 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
}
}
]
]
}

View File

@ -1,18 +0,0 @@
module.exports = {
"extends": "standard",
"parser": "babel-eslint",
"env": {
"es6": true,
"node": true,
},
"rules": {
"indent": [
"error",
2
],
"quotes": [
"error",
"single"
]
}
};

61
embed/.gitignore vendored
View File

@ -1,61 +0,0 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
# next.js build output
.next

View File

@ -1,3 +0,0 @@
{
"schemaPath": "./src/schema.graphql"
}

View File

@ -1,15 +0,0 @@
FROM node:12.5-alpine
LABEL Description="API Service for fetching URL Information for the Social Network Human-Connection.org" Vendor="Human Connection gGmbH" Version="0.0.1" Maintainer="Human Connection gGmbH (developer@human-connection.org)"
EXPOSE 3050
ARG BUILD_COMMIT
ENV BUILD_COMMIT=$BUILD_COMMIT
ARG WORKDIR=/nitro-embed
RUN mkdir -p $WORKDIR
WORKDIR $WORKDIR
RUN apk --no-cache add git
COPY . .
RUN yarn install --frozen-lockfile --non-interactive
CMD ["yarn", "run", "start"]

View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018 Human-Connection
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,53 +0,0 @@
# Nitro-Embed
API Service for fetching URL Information like images, icons, descriptions etc. thourgh OpenGraph, oEmbed and other standards.
> early version of simpler embed api with Metascraper and oEmbed for better results.
![API Screenshot](screenshot.png)
---
## Todo`s
- [x] Metascraper
- [x] oEmbed
- [ ] Temporary API Cache in some DB?
- [ ] Scrape for meta tags
- [ ] Image Caching
---
## Install and start development server
Install dependencies
```shell
yarn install
```
Start development server
```shell
yarn dev
```
## Example Request
Use the following request by posting it against the endpoint or open the url the `yarn dev` script did gave you and fire it there to get your first result.
```grapql
{
embed(url: "https://human-connection.org") {
type
embed
title
description
author
publisher
url
date
image
audio
video
lang
logo
sources
}
}
```

View File

@ -1,54 +0,0 @@
{
"name": "nitro-embed",
"version": "0.0.1",
"description": "API Service for fetching URL Information like images, icons, descriptions etc. thourgh OpenGraph, oEmbed and other standards.",
"main": "src/index.js",
"scripts": {
"dev": "nodemon src/",
"start": "node src/",
"test": "test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Human-Connection/Nitro-Embed.git"
},
"keywords": [
"pengraph",
"oembed"
],
"author": "Grzegorz Leoniec <greg@app-interactive.de> (http://app-interactive.de)",
"license": "MIT",
"bugs": {
"url": "https://github.com/Human-Connection/Nitro-Embed/issues"
},
"homepage": "https://github.com/Human-Connection/Nitro-Embed#readme",
"dependencies": {
"@metascraper/helpers": "^4.8.5",
"apollo-server": "^2.6.7",
"got": "^9.6.0",
"graphql": "^14.0.2",
"lodash": "^4.17.11",
"metascraper": "^4.10.3",
"metascraper-audio": "^5.5.0",
"metascraper-author": "^4.8.5",
"metascraper-clearbit-logo": "^5.3.0",
"metascraper-date": "^4.8.5",
"metascraper-description": "^5.5.0",
"metascraper-image": "^4.8.5",
"metascraper-lang": "^4.8.5",
"metascraper-lang-detector": "^4.8.5",
"metascraper-logo": "^5.5.0",
"metascraper-logo-favicon": "^4.8.5",
"metascraper-publisher": "^4.8.5",
"metascraper-soundcloud": "^5.5.3",
"metascraper-title": "^4.8.5",
"metascraper-url": "^5.5.0",
"metascraper-video": "^4.8.5",
"metascraper-youtube": "^4.8.5",
"request": "^2.88.0",
"request-promise-native": "^1.0.5"
},
"devDependencies": {
"nodemon": "^1.18.9"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 KiB

View File

@ -1,8 +0,0 @@
const fs = require('fs')
const path = require('path')
const { gql } = require('apollo-server')
module.exports = gql(fs
.readFileSync(path.join(__dirname, 'schema.graphql'))
.toString('utf-8'))

View File

@ -1,21 +0,0 @@
const { ApolloServer, gql } = require('apollo-server')
const scraper = require('./scraper.js')
const typeDefs = require('./graphql-schema.js')
const resolvers = {
Query: {
async embed(obj, {url}, ctx, info) {
return await scraper.fetch(url)
}
}
}
const server = new ApolloServer({ typeDefs, resolvers })
if (process.env.NODE_ENV !== 'production') {
process.env.DEBUG = true
}
server.listen({ port: 3050 }).then(({ url }) => {
console.log(`🚀 Nitro Embed - Server is ready at ${url}`)
})

File diff suppressed because it is too large Load Diff