mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-11-11 00:41:45 +08:00
A few changes to support linking to K2 via the new GUI
This commit is contained in:
parent
f9f78968b1
commit
e10e51ab5d
10 changed files with 39 additions and 8 deletions
|
|
@ -2,6 +2,36 @@ const Serialization = require('../serialization');
|
||||||
const {DatabaseConnector} = require('nylas-core');
|
const {DatabaseConnector} = require('nylas-core');
|
||||||
|
|
||||||
module.exports = (server) => {
|
module.exports = (server) => {
|
||||||
|
if (process.env.ALLOW_LIST_ACCOUNTS) {
|
||||||
|
server.route({
|
||||||
|
method: 'GET',
|
||||||
|
path: '/accounts',
|
||||||
|
config: {
|
||||||
|
auth: false,
|
||||||
|
description: 'Returns all accounts, only in dev mode. Only intended to easily link N1.',
|
||||||
|
tags: ['accounts'],
|
||||||
|
},
|
||||||
|
handler: (request, reply) => {
|
||||||
|
DatabaseConnector.forShared().then((db) => {
|
||||||
|
const {Account, AccountToken} = db;
|
||||||
|
|
||||||
|
// N1 assumes that the local sync engine uses the account IDs as the
|
||||||
|
// auth tokens. K2 supports real auth tokens out of the box, but we
|
||||||
|
// create ones that have value = accountId.
|
||||||
|
Account.all().then((accounts) => {
|
||||||
|
Promise.all(
|
||||||
|
accounts.map(({id}) => AccountToken.create({accountId: id, value: id})
|
||||||
|
)).finally(() =>
|
||||||
|
reply(accounts.map((account) =>
|
||||||
|
Object.assign(account.toJSON(), {id: `${account.id}`, auth_token: `${account.id}`})
|
||||||
|
))
|
||||||
|
)
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: '/account',
|
path: '/account',
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
instanceMethods: {
|
instanceMethods: {
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
account_id: this.accountId,
|
account_id: this.accountId,
|
||||||
object: 'contact',
|
object: 'contact',
|
||||||
email: this.email,
|
email: this.email,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
},
|
},
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
object: 'file',
|
object: 'file',
|
||||||
account_id: this.accountId,
|
account_id: this.accountId,
|
||||||
message_id: this.messageId,
|
message_id: this.messageId,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
instanceMethods: {
|
instanceMethods: {
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
account_id: this.accountId,
|
account_id: this.accountId,
|
||||||
object: 'folder',
|
object: 'folder',
|
||||||
name: this.role,
|
name: this.role,
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
instanceMethods: {
|
instanceMethods: {
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
account_id: this.accountId,
|
account_id: this.accountId,
|
||||||
object: 'label',
|
object: 'label',
|
||||||
name: this.role,
|
name: this.role,
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
// Message though and need to protect `this.date` from null
|
// Message though and need to protect `this.date` from null
|
||||||
// errors.
|
// errors.
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
account_id: this.accountId,
|
account_id: this.accountId,
|
||||||
object: 'message',
|
object: 'message',
|
||||||
body: this.body,
|
body: this.body,
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
instanceMethods: {
|
instanceMethods: {
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
type: this.type,
|
type: this.type,
|
||||||
status: this.status,
|
status: this.status,
|
||||||
error: this.error,
|
error: this.error,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = {
|
const response = {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
object: 'thread',
|
object: 'thread',
|
||||||
folders: this.folders,
|
folders: this.folders,
|
||||||
labels: this.labels,
|
labels: this.labels,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ module.exports = (sequelize, Sequelize) => {
|
||||||
instanceMethods: {
|
instanceMethods: {
|
||||||
toJSON: function toJSON() {
|
toJSON: function toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id,
|
id: `${this.id}`,
|
||||||
event: this.event,
|
event: this.event,
|
||||||
object: this.object,
|
object: this.object,
|
||||||
objectId: this.objectId,
|
objectId: this.objectId,
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ apps:
|
||||||
name : api
|
name : api
|
||||||
env :
|
env :
|
||||||
PORT: 5100
|
PORT: 5100
|
||||||
|
ALLOW_LIST_ACCOUNTS : true
|
||||||
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
|
DB_ENCRYPTION_ALGORITHM : "aes-256-ctr"
|
||||||
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"
|
DB_ENCRYPTION_PASSWORD : "d6F3Efeq"
|
||||||
GMAIL_CLIENT_ID : "271342407743-nibas08fua1itr1utq9qjladbkv3esdm.apps.googleusercontent.com"
|
GMAIL_CLIENT_ID : "271342407743-nibas08fua1itr1utq9qjladbkv3esdm.apps.googleusercontent.com"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue