1
import os
from flask import Blueprint, jsonify, send_file
from setting import MDB, COVER_PATH, MUSIC_PATH, QRCODE_PATH
content_bp = Blueprint("content_bp", name)
@content_bp.route("/content_list", methods=["POST"])
def content_list():
content = list(MDB.Content.find({}))
for index, item in enumerate(content):
content[index]["_id"] = str(item.get("_id"))
return jsonify(content)
@content_bp.route("/get_cover/
def get_cover(filename):
cover_path = os.path.join(COVER_PATH, filename) # COVER_PATH = 'Cover' filename = 'xx.jpg'
return send_file(cover_path)
@content_bp.route("/get_music/
def get_music(filename):
music_path = os.path.join(MUSIC_PATH, filename)
return send_file(music_path)
@content_bp.route("/toy_list", methods=["GET", 'POST'])
def toy_list():
toy = list(MDB.Devices.find({}))
for index, item in enumerate(toy):
toy[index]['_id'] = str(item.get('_id'))
return jsonify(toy)
from flask import Blueprint,request,jsonify
from setting import MDB,RET
devices_bp = Blueprint('devices_bp', name)
@devices_bp.route('/scan_qr',methods=['post'])
def scan_qr():
device = request.form.to_dict() # device key
print(device)
device_info = MDB.Devices.find_one(device)
if device_info:
RET['CODE'] = 0
RET['MSG'] = "扫描成功"
RET['DATE'] = device
# 描二维码成功
else:
# 扫描二维码失败 可能不是玩具二维码 数据库中未存在deviceKey
RET['CODE'] = 1
RET['MSG'] = "请扫描玩具二维码"
RET['DATE'] = {}
return jsonify(RET)
@devices_bp.route('/bind_toy',methods=['post'])
def bind_toy():
'''
:return:
'''
toy_info = request.form.to_dict()
toy_info['avatar'] = 'Toy.jpg'
toy_info['bind_user'] = toy_info.pop('user_id') # 删除并给一个新的值
toy_info['friend_list'] = []
MDB.Toys.insert_one(toy_info)
toy_id = MDB.Toys.insert_one(toy_info)
# MDB.Users.update_one({'_id':ObjectId(toy_info["bind_user"])})
RET['CODE'] = 0
RET['MSG'] = "绑定成功"
RET['DATE'] = {}
return jsonify(RET)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 不到万不得已,千万不要去外包
· C# WebAPI 插件热插拔(持续更新中)
· 会议真的有必要吗?我们产品开发9年了,但从来没开过会
· 【译】我们最喜欢的2024年的 Visual Studio 新功能
· 如何打造一个高并发系统?