[TOC]
# :-: 蓝奏云解析
:-: module - reqP.js
```
const request = require("request");
module.exports = function reqP({ url = '', type = 'GET', data = '', headers = {} }) {
const options = {
url,
method: type,
charset: "utf-8",
headers: {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36",
...headers
},
body: data
}
return new Promise((resolve, reject) => {
request(options, function(error, response, conent) {
error ? reject(error) : resolve(conent, response);
});
});
}
```
:-: primary - index.js
```
const cheerio = require("cheerio");
const reqP = require('./reqP.js');
const lanzous = {
parse: function (url, func) {
return reqP({ url }).then(data => {
let $ = cheerio.load(data);
let url = $('body iframe')[0].attribs.src;
return reqP({ url: 'https://www.lanzous.com' + url });
}).then(data => {
let $ = cheerio.load(data);
let sign = $('script').text();
sign = sign.match(/var sg = '(.*?)';/)[1];
return reqP({
type: 'POST',
url: 'https://www.lanzous.com/ajaxm.php',
data: `action=downprocess&sign=${sign}&ves=1`,
headers: {
'content-type': 'application/x-www-form-urlencoded',
'referer': 'https://www.lanzous.com/fn'
}
});
}).then(data => {
data = JSON.parse(data);
return { url, urlParse: data.dom + '/file' + data.url }
});
}
}
lanzous.parse('https://www.lanzous.com/i9nduvg').then(data => {
console.log(data);
});
```
# :-: 连接mysql数据库
```
const mysql = require("mysql");
module.exports = {
exec: function(...arg) {
const connection = mysql.createConnection({
host: "127.0.0.1", // IP
port: "3306", // 端口
user: "root", // 账号
password: "mm123456", // 密码
database: "__schemas" // 数据库
});
connection.connect(); // 连接数据库
connection.query(...arg);
connection.end(); // 关闭数据库
},
getAll: function(func) {
// 查询表(student)
this.exec("select * from student;", (error, result) => func(result));
},
set: function(arr, func) {
this.exec(
"insert into student (`stu_num`,`name`,`age`,`class`) value (?,?,?,?);",
arr,
(error, result) => {
func({ state: typeof result == "object", arr });
}
);
}
};
```
# :-: 服务端·接收上传的文件
```
const multer = require("multer"), // 接收上传的文件
fs = require("fs"),
url = require("url");
const uploadSingle = multer({ dest: "./write/file/" }); // 配置
module.exports = function(app) {
app.post("/api/upload", uploadSingle.single("myFile"), (req, res) => {
// 接收文件 multer
// console.log(req.body);
// console.log(req.file);
const fileObj = req.file;
const fileName = `${(+new Date()).toString(24)}_${fileObj.originalname}`;
fs.rename(fileObj.path, "write\\file\\" + fileName, err => {
if (err) throw err;
fileObj.path = "/api/file/" + fileName;
res.send(fileObj);
});
});
app.get("/api/file/*", (req, res) => {
// 下载文件
const fileName = req.url.split("/api/file/")[1];
// if (fileName) res.send(fs.readFileSync('./write/file/e90e3i9fd_图片1.png'));
if (fileName) res.send(fs.readFileSync("./write/file/" + fileName));
});
};
```
# :-: 数据库连接案例
:-: ../entities/Movie.ts
```ts
import "reflect-metadata";
import {
IsNotEmpty, ArrayMinSize,
IsInt, Min, Max, IsArray
} from "class-validator";
import { Type, plainToClass } from "class-transformer";
import { BaseEntity } from "./BaseEntity";
export class Movie extends BaseEntity {
@IsNotEmpty({ message: "电影名称不能为空" })
@Type(() => String)
public name: string;
@IsNotEmpty({ message: "电影类型不能为空" })
@ArrayMinSize(1, { message: "电影类型成员至少有一个" })
@IsArray({ message: "电影类型必须为数组" })
@Type(() => String)
public types: string[];
@IsNotEmpty({ message: "上映地区不能为空" })
@ArrayMinSize(1, { message: "上映地区成员至少有一个" })
@IsArray({ message: "上映地区必须为数组" })
@Type(() => String)
public areas: string[];
@IsNotEmpty({ message: "时长不能为空" })
@IsInt({ message: "时长必须为整数" })
@Min(1, { message: "时长至少一分钟" })
@Max(999999, { message: "时长已达到上限" })
@Type(() => Number)
public timeLong: number;
@IsNotEmpty({ message: "是否热映不能为空" })
@Type(() => Boolean)
public isHot: boolean;
@IsNotEmpty({ message: "是否即将上映不能为空" })
@Type(() => Boolean)
public isClassic: boolean;
@Type(() => String)
public description?: string;
@Type(() => String)
public poster?: string;
}
```
:-: ./MovieSchema.ts
```ts
import Mongoose from "mongoose";
import { Movie } from "../entities/Movie";
export interface IMovie extends Movie, Mongoose.Document {}
const movieSchema = new Mongoose.Schema<IMovie>(
{
name: String, areas: [String],
tyoes: [String], timeLong: Number,
isHot: Boolean, isComing: Boolean,
isClassic: Boolean, description: String,
poster: String
},
{ versionKey: false }
);
export default Mongoose.model<IMovie>("Movie", movieSchema);
```
:-: ./index.ts
```ts
import Mongoose from "mongoose";
import MovieModel from "./MovieSchema";
Mongoose.connect("mongodb://localhost:27017/moviedb", {
useNewUrlParser: true
}).then(() => console.log("mongodb -- 连接成功"));
export { MovieModel };
```
- 前端工具库
- HTML
- CSS
- 实用样式
- JavaScript
- 模拟运动
- 深入数组扩展
- JavaScript_补充
- jQuery
- 自定义插件
- 网络 · 后端请求
- css3.0 - 2019-2-28
- 选择器
- 边界样式
- text 字体系列
- 盒子模型
- 动图效果
- 其他
- less - 用法
- scss - 用法 2019-9-26
- HTML5 - 2019-3-21
- canvas - 画布
- SVG - 矢量图
- 多媒体类
- H5 - 其他
- webpack - 自动化构建
- webpack - 起步
- webpack -- 环境配置
- gulp
- ES6 - 2019-4-21
- HTML5补充 - 2019-6-30
- 微信小程序 2019-7-8
- 全局配置
- 页面配置
- 组件生命周期
- 自定义组件 - 2019-7-14
- Git 基本操作 - 2019-7-16
- vue框架 - 2019-7-17
- 基本使用 - 2019-7-18
- 自定义功能 - 2019-7-20
- 自定义组件 - 2019-7-22
- 脚手架的使用 - 2019-7-25
- vue - 终端常用命令
- Vue Router - 路由 (基础)
- Vue Router - 路由 (高级)
- 路由插件配置 - 2019-7-29
- 路由 - 一个实例
- VUEX_数据仓库 - 2019-8-2
- Vue CLI 项目配置 - 2019-8-5
- 单元测试 - 2019-8-6
- 挂载全局组件 - 2019-11-14
- React框架
- React基本使用
- React - 组件化 2019-8-25
- React - 组件间交互 2019-8-26
- React - setState 2019-11-19
- React - slot 2019-11-19
- React - 生命周期 2019-8-26
- props属性校验 2019-11-26
- React - 路由 2019-8-28
- React - ref 2019-11-26
- React - Context 2019-11-27
- PureComponent - 性能优化 2019-11-27
- Render Props VS HOC 2019-11-27
- Portals - 插槽 2019-11-28
- React - Event 2019-11-29
- React - 渲染原理 2019-11-29
- Node.js
- 模块收纳
- dome
- nodejs - tsconfig.json
- TypeScript - 2020-3-5
- TypeScript - 基础 2020-3-6
- TypeScript - 进阶 2020-3-9
- Ordinary小助手
- uni-app
- 高德地图api
- mysql
- EVENTS
- 笔记
- 关于小程序工具方法封装
- Tool/basics
- Tool/web
- parsedUrl
- request