瀏覽代碼

Merge branch 'emoji'

sbkwgh 8 年之前
父節點
當前提交
c92d5737aa

+ 2 - 0
migrations/20170925191833-create-bans-table.js

@@ -24,6 +24,8 @@ module.exports = {
       UserId: Sequelize.INTEGER,
       createdAt: Sequelize.DATE,
       updatedAt: Sequelize.DATE
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925200317-create-categories-table.js

@@ -21,6 +21,8 @@ module.exports = {
         unique: true
       },
       color: Sequelize.STRING
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925201609-create-ips-table.js

@@ -12,6 +12,8 @@ module.exports = {
       updatedAt: Sequelize.DATE,
 
       ip: Sequelize.STRING(45)
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925201924-create-logs-table.js

@@ -24,6 +24,8 @@ module.exports = {
       ThreadId: Sequelize.INTEGER,
       UserId: Sequelize.INTEGER,
       SessionUserId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925202317-create-notifications-table.js

@@ -21,6 +21,8 @@ module.exports = {
       },
       type: Sequelize.ENUM('mention', 'thread update', 'reply'),
       UserId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925202519-create-pollanswers-table.js

@@ -16,6 +16,8 @@ module.exports = {
         allowNull: false
       },
       PollQuestionId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925202651-create-pollquestions-table.js

@@ -16,6 +16,8 @@ module.exports = {
         allowNull: false
       },
       UserId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925202801-create-pollvotes-table.js

@@ -14,6 +14,8 @@ module.exports = {
       UserId: Sequelize.INTEGER,
       PollAnswerId: Sequelize.INTEGER,
       PollQuestionId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925203055-create-postnotifications-table.js

@@ -14,6 +14,8 @@ module.exports = {
       UserId: Sequelize.INTEGER,
       PostId: Sequelize.INTEGER,
       NotificationId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925203433-create-posts-table.js

@@ -25,6 +25,8 @@ module.exports = {
       UserId: Sequelize.INTEGER,
       ThreadId: Sequelize.INTEGER,
       replyId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925204011-create-reports-table.js

@@ -18,6 +18,8 @@ module.exports = {
 
       FlaggedByUserId: Sequelize.INTEGER,
       PostId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925204327-create-settings-table.js

@@ -13,6 +13,8 @@ module.exports = {
       
       forumName: Sequelize.STRING,
       forumDescription: Sequelize.STRING
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925204827-create-threads-table.js

@@ -28,6 +28,8 @@ module.exports = {
       CategoryId: Sequelize.INTEGER,
       UserId: Sequelize.INTEGER,
       PollQuestionId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925205531-create-user_post-table.js

@@ -8,6 +8,8 @@ module.exports = {
       
       PostId: Sequelize.INTEGER,
       UserId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925205649-create-userip-table.js

@@ -8,6 +8,8 @@ module.exports = {
 
       IpId: Sequelize.INTEGER,
       UserId: Sequelize.INTEGER
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925205832-create-users-table.js

@@ -25,6 +25,8 @@ module.exports = {
         type: Sequelize.BOOLEAN,
         defaultValue: false
       }
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 2 - 0
migrations/20170925210453-create-admintokens-table.js

@@ -12,6 +12,8 @@ module.exports = {
       updatedAt: Sequelize.DATE,
       
       token: Sequelize.STRING
+    }, {
+      charset: 'utf8mb4'
     })
   },
 

+ 12 - 2
models/index.js

@@ -6,14 +6,24 @@ const config = require('../config/config.json');
 const env = process.env.NODE_ENV || 'development';
 const db = {};
 
+let options = {
+	define: {
+		charset: 'utf8mb4',
+		collate: 'utf8mb4_general_ci'
+	},
+	dialectOptions: {
+		charset: 'utf8mb4'
+	}
+}
 if(env === 'production') {
-	var sequelize = new Sequelize(process.env.DATABASE_URL)
+	var sequelize = new Sequelize(process.env.DATABASE_URL, options)
 } else {
 	var sequelize = new Sequelize(
 		config[env].database, config[env].username, config[env].password, {
 			host: config[env].host,
 			dialect: config[env].dialect,
-			logging: false
+			logging: false,
+			...options
 		}
 	);
 }

+ 16 - 0
test/thread_post.js

@@ -675,6 +675,22 @@ describe('Thread and post', () => {
 		})
 	})
 
+	describe('POST utf8', () => {
+		it('should allow emojis', async () => {
+			let res = await userAgent
+				.post('/api/v1/post')
+				.set('content-type', 'application/json')
+				.send({
+					content: '😂😀',
+					threadId: 1
+				})
+
+			res.should.be.json
+			res.should.have.status(200)
+			res.body.should.have.property('content', '<p>😂😀</p>\n')
+		})
+	})
+
 	describe('DELETE /post/:id', () => {
 		let threadId
 		let postId