initial commit

This commit is contained in:
nihonium 2023-01-15 13:53:21 +03:00
commit 3b3c9a9417
Signed by: nihonium
GPG key ID: 0251623741027CFC
258 changed files with 20086 additions and 0 deletions

View file

@ -0,0 +1,12 @@
FROM node:alpine
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json ./
RUN npm install -g npm@8.19.2 && npm config rm proxy && npm config rm https-proxy
RUN npm install
COPY . .
RUN npm run build
EXPOSE 3000
CMD npm run start

View file

@ -0,0 +1,34 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

View file

@ -0,0 +1,10 @@
export interface SignIn {
username: string,
password: string,
}
export interface SignUp {
username: string;
password: string;
}

View file

@ -0,0 +1,12 @@
export interface Blog_int {
url: string,
is_private: string,
}
export interface Post_int {
posts: {
title: string;
body: string;
blog_url:string;
}
}

View file

@ -0,0 +1,10 @@
.container {
display: grid;
grid-template-columns: 1fr auto 1fr;
grid-template-rows: 100px 1fr 100px;
min-height: 100vh;
grid-template-areas:
". . ."
". form .";
}

View file

@ -0,0 +1,5 @@
import {DataHTMLAttributes, DetailedHTMLProps, HTMLAttributes, ReactNode} from "react";
export interface LayoutProps {
children: ReactNode;
}

View file

@ -0,0 +1,21 @@
import {LayoutProps} from "./Layout.props";
import styles from "./Layout.module.css"
import cn from "classnames";
import {Component, FunctionComponent} from "react";
const Layout = ({ children }: LayoutProps): JSX.Element => {
return(
<div className={styles.container} >
{children}
</div>
);
};
export const withLayout = <T extends Record<string, unknown>>(Component: FunctionComponent<T>) => {
return function withLayoutComponent(props: T): JSX.Element {
return(
<Layout>
<Component {...props} />
</Layout>
);
};
};

View file

@ -0,0 +1,84 @@
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
grid-template-rows: 100px 1fr;
min-height: 100vh;
grid-template-areas:
". . header . utils"
". post . . .";
}
.utils{
display: grid;
grid-template-areas:
"signout "
"create "
"blog_list "
"read_post"
"posts_list";
grid-area: utils;
max-height: 50px;
max-width: 150px;
}
.signout{
grid-area: signout;
}
.create{
grid-area: create;
}
.blog_list{
grid-area: blog_list;
}
.post_read{
grid-area: post_read;
}
.posts_list{
grid-area: posts_list;
}
.mybtn{
margin: 5px;
--bs-btn-color: #fff;
--bs-btn-bg: #6c757d;
--bs-btn-border-color: #6c757d;
--bs-btn-hover-color: #fff;
--bs-btn-hover-bg: #5c636a;
--bs-btn-hover-border-color: #565e64;
--bs-btn-focus-shadow-rgb: 130,138,145;
--bs-btn-active-color: #fff;
--bs-btn-active-bg: #565e64;
--bs-btn-active-border-color: #51585e;
--bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
--bs-btn-disabled-color: #fff;
--bs-btn-disabled-bg: #6c757d;
--bs-btn-disabled-border-color: #6c757d;
user-select: none;
border: var(--bs-btn-border-width) solid var(--bs-btn-border-color);
border-radius: var(--bs-btn-border-radius);
background-color: var(--bs-btn-bg);
transition: color .15s ease-in-out,background-color .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
border-radius: 5px;
font-family: var(--bs-btn-font-family);
font-size: var(--bs-btn-font-size);
font-weight: var(--bs-btn-font-weight);
line-height: var(--bs-btn-line-height);
color: var(--bs-btn-color);
text-align: center;
text-decoration: none;
}
.mybtn:hover{
color: var(--bs-btn-hover-color);
background-color: var(--bs-btn-hover-bg);
border-color: var(--bs-btn-hover-border-color);
}
.header{
grid-area: header;
}

View file

@ -0,0 +1,5 @@
import {DataHTMLAttributes, DetailedHTMLProps, HTMLAttributes, ReactNode} from "react";
export interface LayoutProps {
children: ReactNode;
}

View file

@ -0,0 +1,155 @@
import {LayoutProps} from "./Layout.props";
import styles from "./Layout.module.css"
import styles_post from "./Post/Post.module.css"
import {Post} from "./Post/Post";
import cn from "classnames";
import {Component, FunctionComponent} from "react";
import {useContext, useEffect, useState} from "react";
import Cookie from 'js-cookie';
import axios from "axios";
import {Post_int, Blog_int} from "../interfaces/blog_interface"
import blog from "../pages/blog";
import {Button, Form, Input} from "reactstrap";
const Layout = ({ children }: LayoutProps): JSX.Element => {
const [data, setData] = useState(<></>);
const [file, setFile] = useState()
function handleChange(event) {
setFile(event.target.files[0])
}
useEffect(() => {
//get_posts()
get_blog()
}, []);
function get_blog(){
if (localStorage.getItem("blog_url") == null){
axios.get<Blog_int>('http://10.50.20.5:13377/api/blog', {withCredentials: true}).then(response => {
localStorage.setItem('blog_url', response.data.url);
get_posts(response.data.url)
})
} else{
get_posts(localStorage.getItem("blog_url"))
}
}
function get_posts(blog_url: string){
axios.get<Post_int>('http://10.50.20.5:13377/api/blog/'.concat(blog_url), {withCredentials: true}).then(response => {
let jsonDataPosts = JSON.parse(JSON.stringify(response.data.posts))
let mydata: JSX.Element
jsonDataPosts.forEach((post: Post_int) => {
mydata = (
<>
<Post content={post.posts.body} title={post.posts.title}/>
{mydata}
</>)
setData(mydata)
}
)
})
}
function sign_out(){
localStorage.removeItem("blog_url")
Cookie.remove('sessions')
window.location.href = "/auth"
}
function create_post(){
axios.post("http://10.50.20.5:13377/api/blog/".concat(localStorage.getItem("blog_url")).concat("/").concat("create_post"), {"title": "test", "body":"test"}, {withCredentials: true}).then( response => {window.location.reload()})
}
function blog_list(){
axios.get("http://10.50.20.5:13377/api/blogs", {withCredentials: true}).then( response => {
let jsonDataBlogs = JSON.parse(JSON.stringify(response.data))
let mydata: JSX.Element
jsonDataBlogs.forEach((post: Blog_int) => {
mydata = (
<>
<pre><code>post.url</code></pre>
<pre><code>post.is_private</code></pre>
{mydata}
</>
)
setData(mydata)
}
)
})
}
function upload_file(){
}
function handleSubmit() {
event.preventDefault()
const url = 'http://10.50.20.5:13377/file/upload?path=file_storage';
const formData = new FormData();
formData.append('file', file);
const config = {
withCredentials: true,
headers: {
'content-type': 'multipart/form-data',
},
};
axios.post(url, formData, config).then((response) => {
console.log(response.data);
});
}
function read_post(){
let num_post = prompt("Input id your post")
axios.get("http://10.50.20.5:13377/api/blog/".concat(localStorage.getItem("blog_url")).concat("/").concat("post").concat("/").concat(num_post), {withCredentials: true}).then( response => {
let jsonDataBlogs = JSON.parse(JSON.stringify(response.data))
let mydata: JSX.Element
jsonDataBlogs.forEach((post: Blog_int) => {
mydata = (
<>
<pre><code>{mydata}</code></pre>
</>
)
setData(mydata)
}
)
})
}
return(
<div className={styles.container} >
<div className={styles.utils}>
<button className={cn(styles.signout, styles.mybtn)} onClick={function (){sign_out()}}>Sign Out</button>
<button className={cn(styles.create, styles.mybtn)} onClick={function (){create_post()}}>Create Post</button>
<button className={cn(styles.blog_list, styles.mybtn)} onClick={function (){blog_list()}}>Blogs List</button>
<button className={cn(styles.read_post, styles.mybtn)} onClick={function (){read_post()}}>Read Post</button>
<button className={cn(styles.posts_list, styles.mybtn)} onClick={function (){get_posts(localStorage.getItem("blog_url"))}}>Posts List</button>
<Form onSubmit={handleSubmit}>
<h2>Upload</h2>
<Input type="file" onChange={handleChange}></Input>
<button type="submit">Upload</button>
</Form>
</div>
<h1 className={styles.header}>Test Header</h1>
<Post className={styles_post.post} content={"test"} title={"test"}/>
{children}
</div>
);
};
export const withLayout = <T extends Record<string, unknown>>(Component: FunctionComponent<T>) => {
return function withLayoutComponent(props: T): JSX.Element {
return(
<Layout>
<Component {...props} />
</Layout>
);
};
};

View file

@ -0,0 +1,20 @@
.post{
grid-area: post;
display: grid;
grid-template-columns: 0.5fr 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
grid-template-areas:
"title . ."
". content .";
max-height: 200px;
}
.title{
grid-area: title;
}
.content{
grid-area: content;
}

View file

@ -0,0 +1,7 @@
import {DataHTMLAttributes, DetailedHTMLProps, HTMLAttributes, InputHTMLAttributes, ReactNode} from "react";
export interface PostProps extends DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
content: string;
title: string;
}

View file

@ -0,0 +1,14 @@
import {PostProps} from "./Post.props";
import styles from "./Post.module.css"
import cn from "classnames";
export const Post = ({className, title="", content="", ...props}: PostProps): JSX.Element => {
return(
<div className={cn(styles.post, className, {
})} {...props}>
<img src={"http://10.50.20.5:13377/image/images?filename=standart_image.png"}/>
<h1 className={styles.title}>{title}</h1>
<p className={styles.content}>{content}</p>
</div>
);
}

View file

@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.

View file

@ -0,0 +1,10 @@
module.exports = {
webpack(config){
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
});
return config;
},
reactStrictMode: true,
};

5774
services/myblog/frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,29 @@
{
"name": "top-app",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.2.5",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/classnames": "^2.3.1",
"@types/node": "^18.7.14",
"@types/react": "^18.0.18",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"axios": "^0.27.2",
"bootstrap": "^5.2.0",
"eslint": "^8.23.0",
"eslint-config-next": "12.2.5",
"js-cookie": "^3.0.1",
"jwt-decode": "^3.1.2",
"reactstrap": "^9.1.4",
"typescript": "^4.8.2"
}
}

View file

@ -0,0 +1,7 @@
import '../styles/globals.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp

View file

@ -0,0 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}

View file

@ -0,0 +1,67 @@
import {withLayout} from "../layout_auth/Layout";
import {useState} from "react";
import axios from 'axios';
import Cookie from 'js-cookie';
import {useRouter} from "next/router";
import jwtDecode from "jwt-decode";
import 'bootstrap/dist/css/bootstrap.min.css';
import {
Container, Row, Col, Form, Input, Button, Navbar, Nav,
NavbarBrand, NavLink, NavItem, UncontrolledDropdown,
DropdownToggle, DropdownMenu, DropdownItem
} from 'reactstrap';
function setUserIDLocalStrorage(token: string): void{
const decoded_token = jwtDecode<{user:{ID:string} }>(token);
localStorage.setItem('user_id', decoded_token.user.ID);
}
function Home() {
const router = useRouter();
const initialFormData = Object.freeze({
username: "",
password: ""
});
const [formData, updateFormData] = useState(initialFormData);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateFormData({
...formData,
// Trimming any whitespace
[e.target.name]: e.target.value.trim()
});
};
const handleSubmit = (e: React.ChangeEvent<HTMLFormElement>) => {
e.preventDefault();
axios.post('http://10.50.20.5:13377/api/auth/sign_in', formData, {withCredentials: true})
.then(function(response){
let cook = response.headers['set-cookie']
//Cookies.set('api_session', cook)
router.push('/blog');
//Perform action based on response
})
.catch(function(error){
console.log(error);
alert("Bad creads")
//Perform action based on error
});
// ... submit to API or something
};
return (
<>
<form style={{gridArea: "form"}} onSubmit={handleSubmit}>
<h1>Sign In</h1>
<Input onChange={handleChange} name={"username"} placeholder={"Username"}/>
<Input onChange={handleChange} name={"password"} placeholder={"Password"}/>
<Button>Sign In</Button>
<NavLink href={"/register"} style={{justifySelf: "center", alignSelf: "center"}}>Sign out</NavLink>
</form>
</>
);
}
export default withLayout(Home);

View file

@ -0,0 +1,23 @@
import {withLayout} from "../layout_blog/Layout";
import {useState} from "react";
import axios from 'axios';
import Cookie from 'js-cookie';
import {useRouter} from "next/router";
import jwtDecode from "jwt-decode";
import 'bootstrap/dist/css/bootstrap.min.css';
import {
Container, Row, Col, Form, Input, Button, Navbar, Nav,
NavbarBrand, NavLink, NavItem, UncontrolledDropdown,
DropdownToggle, DropdownMenu, DropdownItem
} from 'reactstrap';
function Home() {
return (
<>
</>
);
}
export default withLayout(Home);

View file

@ -0,0 +1,56 @@
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import {useRouter} from "next/router";
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>MyBlog</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<div className={styles.grid}>
<a href="/auth" className={styles.card}>
<h2>Sign in MyBlog</h2>
</a>
<a href="/register" className={styles.card}>
<h2>Register in MyBLog</h2>
</a>
<a
href="/blog"
className={styles.card}
>
<h2>Go to blog &rarr;</h2>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
</div>
)
}

View file

@ -0,0 +1,59 @@
import {withLayout} from "../layout_auth/Layout";
import {useState} from "react";
import axios from 'axios';
import 'bootstrap/dist/css/bootstrap.min.css';
import {useRouter} from "next/router";
import {
Container, Row, Col, Form, Input, Button, Navbar, NavLink
} from 'reactstrap';
function Home() {
const router = useRouter();
const initialFormData = Object.freeze({
username: "",
password: ""
});
const [formData, updateFormData] = useState(initialFormData);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
updateFormData({
...formData,
// Trimming any whitespace
[e.target.name]: e.target.value.trim()
});
};
const handleSubmit = (e: React.ChangeEvent<HTMLFormElement>) => {
e.preventDefault();
axios.post('http://10.50.20.5:13377/api/auth/sign_up', formData)
.then(function(response){
router.push('/auth');
//Perform action based on response
})
.catch(function(error){
console.log(error);
//Perform action based on error
});
// ... submit to API or something
};
return (
<>
<form style={{gridArea: "form"}} onSubmit={handleSubmit}>
<h1>Sign Out</h1>
<Input onChange={handleChange} name={"username"} placeholder={"Username"}/>
<Input onChange={handleChange} type={"password"} name={"password"} placeholder={"Password"}/>
<Input onChange={handleChange} type={"password"} name={"password_repeat"} placeholder={"Password (repeat)"}/>
<Button>Sign Out</Button>
<NavLink href={"/auth"} style={{justifySelf: "center", alignSelf: "center"}}>Sign In</NavLink>
</form>
</>
);
}
export default withLayout(Home);

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View file

@ -0,0 +1,4 @@
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,116 @@
.container {
padding: 0 2rem;
}
.main {
min-height: 100vh;
padding: 4rem 0;
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.footer {
display: flex;
flex: 1;
padding: 2rem 0;
border-top: 1px solid #eaeaea;
justify-content: center;
align-items: center;
}
.footer a {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
}
.title a {
color: #0070f3;
text-decoration: none;
}
.title a:hover,
.title a:focus,
.title a:active {
text-decoration: underline;
}
.title {
margin: 0;
line-height: 1.15;
font-size: 4rem;
}
.title,
.description {
text-align: center;
}
.description {
margin: 4rem 0;
line-height: 1.5;
font-size: 1.5rem;
}
.code {
background: #fafafa;
border-radius: 5px;
padding: 0.75rem;
font-size: 1.1rem;
font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono,
Bitstream Vera Sans Mono, Courier New, monospace;
}
.grid {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
max-width: 800px;
}
.card {
margin: 1rem;
padding: 1.5rem;
text-align: left;
color: inherit;
text-decoration: none;
border: 1px solid #eaeaea;
border-radius: 10px;
transition: color 0.15s ease, border-color 0.15s ease;
max-width: 300px;
}
.card:hover,
.card:focus,
.card:active {
color: #0070f3;
border-color: #0070f3;
}
.card h2 {
margin: 0 0 1rem 0;
font-size: 1.5rem;
}
.card p {
margin: 0;
font-size: 1.25rem;
line-height: 1.5;
}
.logo {
height: 1em;
margin-left: 0.5rem;
}
@media (max-width: 600px) {
.grid {
width: 100%;
flex-direction: column;
}
}

View file

@ -0,0 +1,16 @@
html,
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
a {
color: inherit;
text-decoration: none;
}
* {
box-sizing: border-box;
}

View file

@ -0,0 +1,31 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": false,
"skipLibCheck": true,
"strict": false,
"strictPropertyInitialization": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

File diff suppressed because it is too large Load diff