Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maximousblk committed Jul 26, 2021
0 parents commit 6d95f25
Show file tree
Hide file tree
Showing 19 changed files with 3,869 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next", "next/core-web-vitals"]
}
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LICENSE @nestdotland/core
/.github/ @nestdotland/core
76 changes: 76 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

open_collective: nest-land
42 changes: 42 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Lint

on:
push:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Node 16
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install Depedencies
run: yarn

- name: Lint
run: yarn lint

fmt:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Setup Node 16
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install Depedencies
run: yarn

- name: Format
run: yarn fmt
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
34 changes: 34 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 nest.land Team

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.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Nest CDN

A simple proxy to mask the long arweave URLs.

## License

The contents of this repository are licensed under [The MIT license](LICENSE).
3 changes: 3 additions & 0 deletions lib/supabase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createClient } from '@supabase/supabase-js';

export const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
3 changes: 3 additions & 0 deletions next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />
20 changes: 20 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
reactStrictMode: true,
async rewrites() {
return [
{
source: '/:path*',
destination: '/api?s=:path*',
},
];
},
async redirects() {
return [
{
source: '/',
destination: 'https://nest.land',
permanent: true,
},
];
},
};
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "cdn",
"private": true,
"author": "Maximous Black <[email protected]>",
"license": "MIT",
"repository": "https://github.com/nestdotland/cdn",
"description": "Nest CDN",
"scripts": {
"ts": "ts-node",
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "echo no tests implemented",
"fmt": "prettier --check .",
"fmt:fix": "prettier --write ."
},
"dependencies": {
"@supabase/supabase-js": "^1.21.0",
"next": "^11.0.1",
"node-fetch": "^2.6.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@types/node-fetch": "^2.5.12",
"@types/react": "^17.0.15",
"eslint": "7.31.0",
"eslint-config-next": "^11.0.1",
"prettier": "^2.3.2",
"ts-node": "^10.1.0",
"typescript": "^4.3.5"
},
"prettier": {
"singleQuote": true,
"printWidth": 120
},
"engines": {
"node": "16"
}
}
65 changes: 65 additions & 0 deletions pages/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { NextApiHandler, NextApiResponse } from 'next';
import fetch from 'node-fetch';
import { supabase } from '@/lib/supabase';

const handler: NextApiHandler = async (req, res) => {
const slug = req.query.s as string;
const match = /^([^\/@]+)\/([^\/@]+)@([^\/]+)\/(.*)$/.exec(slug);

if (!match) {
res.status(400);
res.end(`Invalid URL`);
}

const [, authorName, moduleName, versionName, filepath] = match;

if (!authorName) {
res.status(400);
res.end(`Author not provided!`);
} else if (!moduleName) {
res.status(400);
res.end(`Module not provided!`);
} else if (!versionName) {
res.status(400);
res.end(`Version not provided!`);
} else if (!filepath) {
res.status(400);
res.end(`Path not provided!`);
}

let { data: Files, error } = await supabase
.from('File')
.select('url, mimeType')
.eq('authorName', authorName)
.eq('moduleName', moduleName)
.eq('versionName', versionName)
.eq('path', filepath);

if (error) {
res.status(500);
res.end(`Internal Server Error`);
throw new Error(`${error.message} (hint: ${error.hint})`);
}

if (Files.length < 1) {
res.status(404);
res.end('Not Found');
} else if (Files.length > 1) {
// more than one files with same primary key @@id([author, module, version, path])
console.error("Wait, that's illegal!!!");
res.status(500);
res.end(`Internal Server Error`);
} else {
const { url, mimeType } = Files[0];

const data = await fetch(url);

res.setHeader('Content-Type', mimeType);
res.setHeader('Cache-Control', ['maxage=86400', 's-maxage=86400', 'stale-if-error=1', 'immutable']);

res.status(data.status);
data.body.pipe(res);
}
};

export default handler;
Binary file added public/favicon.ico
Binary file not shown.
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": "./",
"paths": {
"@/lib/*": ["lib/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Loading

0 comments on commit 6d95f25

Please sign in to comment.