Giter VIP home page Giter VIP logo

photo-album's Introduction

Serverless 相册

在线体验 (使用手机访问体验最佳)

Build Status semantic-release

Serverless 相册应用,上传照片可以智能识别,添加属性标签

注意:目前并未添加用户登录逻辑,只是在用户第一次访问应用时,自动生成了一个 uuid 作为唯一标识,然后存放到了 LocalStorage 中,如果是发布到小程序,开发者可以自行添加登录逻辑。

功能

使用的云端服务

注意:由于图片识别依赖腾讯云的 图像标签 服务,使用前请到控制台开通。

TODO

  • 列表页
  • 图片上传
  • 图片自动添加标签
  • 图片自动添加描述
  • 相册分类
  • 用户登录
  • 小程序授权登录(将单独使用 weapp 分支开发)

目录介绍

.
├── README.md               // 说明文档
├── client                  // 客户端代码
├── cos                     // Serverless cos 组件配置
├── db                      // Serverless cynosdb(mysql) 组件配置
├── docker-compose.yml      // Docker compose 配置,方便本地模拟数据库链接
├── layer                   // Serverless layer 组件配置
├── serverless.yml          // Serverless express 组件配置
├── sls.ts                  // 云函数入口文件
├── src                     // 服务端代码
├── tsconfig.json           // Typescript 配置
└── vpc                     // Serverless vpc 组件配置

演示

使用

$ git clone https://github.com/serverless-plus/photo-album.git

或者通过 serverless 命令初始化:

$ sls init photo-album

注意:通过 sls init 命令初始化时,会自动安装项目的依赖(执行 npm install),时间可能比较长,请耐心等待。如果由于网络原因导致依赖安装失败,可以重新进入项目目录,执行 npm install 来安装依赖。

本地开发

安装依赖:

$ npm install && cd client && npm install

创建用来存储相片的存储桶:

$ npm run deploy:cos

本地启动 Docker 服务:

$ npm run docker:up

复制 .env.example.env,然后配置成个人账号,主要需要配置(TENCENT_APP_IDTENCENT_SECRET_IDTENCENT_SECRET_KEY):

$ cp .env.example .env

启动服务端

$ npm run dev:server

启动客户端:

$ npm run dev:client

部署应用

部署数据库

Serverless MYSQL 数据库,需要配置私有网络(VPC),隐私我们需要先创建私有网络:

$ npm run deploy:vpc

VPC 创建成功后,再部署数据库

$ npm run deploy:db

创建存储桶

创建用来存储相片的存储桶:

$ npm run deploy:cos

部署层

针对 Node.js 项目, 我们可以将 node_modules 文件夹部署到层,第一次将 node_modules 部署到层后,就不用再次重复部署了,这样可以打打减少代码上传体积。

$ npm run deploy:layer

注意: 层部署成功后,如果我们新增了模块依赖(改变了 node_modules)就需要再次执行部署层命令。

部署服务端代码

$ npm run deploy:server

部署客户端代码

$ npm run deploy:client

常见问题

License

MIT License

Copyright (c) 2020 Serverless Plus

photo-album's People

Contributors

yugasun avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

photo-album's Issues

npm run dev:server报错

描述

我按照文档操作,执行npm run dev:server的时候,先是出现 ts-node 报错。
于是我安装了 ts-node,重复执行命令,出现以下报错:

➜ npm run dev:server  

> [email protected] dev:server
> NODE_ENV=development ts-node src/server.ts

(node:10467) [SEQUELIZE0002] DeprecationWarning: The logging-option should be either a function or false. Default: console.log
(Use `node --trace-deprecation ...` to show where the warning was created)
[Sequelize] Try to create database photo-album
ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:5432
    at ConnectionManager.connect (/Users/cooper/github_project/photo-album/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:116:17)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at ConnectionManager._connect (/Users/cooper/github_project/photo-album/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:318:24)
    at /Users/cooper/github_project/photo-album/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:250:32
    at ConnectionManager.getConnection (/Users/cooper/github_project/photo-album/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:280:7)
    at /Users/cooper/github_project/photo-album/node_modules/sequelize/lib/sequelize.js:613:26
    at Object.initDatabase (/Users/cooper/github_project/photo-album/src/sequelize.ts:42:7)
    at initServer (/Users/cooper/github_project/photo-album/src/server.ts:12:3) {
  parent: Error: connect ECONNREFUSED 127.0.0.1:5432
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16) {
    errno: -61,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 5432,
    fatal: true
  },
  original: Error: connect ECONNREFUSED 127.0.0.1:5432
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16) {
    errno: -61,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 5432,
    fatal: true
  }
}
  App is running at http://localhost:3000 in development mode
  Press CTRL-C to stop

而 docker 的 dashboard 里面,mysql 是红色未启动状态。
image

环境

macOS bigsur
nodejs 16.1.0
npm 7.12.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.