forked from FoundKeyGang/FoundKey
This commit is contained in:
parent
1968d18e3f
commit
31006fbc25
10 changed files with 65 additions and 24 deletions
|
@ -43,8 +43,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Get 'geo' parameter
|
// Get 'geo' parameter
|
||||||
const [geo, geoErr] = $(params.geo).optional.nullable.strict.object()
|
const [geo, geoErr] = $(params.geo).optional.nullable.strict.object()
|
||||||
.have('latitude', $().number().range(-90, 90))
|
.have('coordinates', $().array().length(2)
|
||||||
.have('longitude', $().number().range(-180, 180))
|
.item(0, $().number().range(-180, 180))
|
||||||
|
.item(1, $().number().range(-90, 90)))
|
||||||
.have('altitude', $().nullable.number())
|
.have('altitude', $().nullable.number())
|
||||||
.have('accuracy', $().nullable.number())
|
.have('accuracy', $().nullable.number())
|
||||||
.have('altitudeAccuracy', $().nullable.number())
|
.have('altitudeAccuracy', $().nullable.number())
|
||||||
|
|
|
@ -35,8 +35,7 @@ export type IPost = {
|
||||||
reactionCounts: any;
|
reactionCounts: any;
|
||||||
mentions: mongo.ObjectID[];
|
mentions: mongo.ObjectID[];
|
||||||
geo: {
|
geo: {
|
||||||
latitude: number;
|
coordinates: number[];
|
||||||
longitude: number;
|
|
||||||
altitude: number;
|
altitude: number;
|
||||||
accuracy: number;
|
accuracy: number;
|
||||||
altitudeAccuracy: number;
|
altitudeAccuracy: number;
|
||||||
|
@ -97,6 +96,7 @@ export const pack = async (
|
||||||
delete _post._id;
|
delete _post._id;
|
||||||
|
|
||||||
delete _post.mentions;
|
delete _post.mentions;
|
||||||
|
if (_post.geo) delete _post.geo.type;
|
||||||
|
|
||||||
// Parse text
|
// Parse text
|
||||||
if (_post.text) {
|
if (_post.text) {
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
<div class="tags" v-if="p.tags && p.tags.length > 0">
|
<div class="tags" v-if="p.tags && p.tags.length > 0">
|
||||||
<router-link v-for="tag in p.tags" :key="tag" :to="`/search?q=#${tag}`">{{ tag }}</router-link>
|
<router-link v-for="tag in p.tags" :key="tag" :to="`/search?q=#${tag}`">{{ tag }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.latitude},${p.geo.longitude}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.coordinates[1]},${p.geo.coordinates[0]}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
||||||
<div class="map" v-if="p.geo" ref="map"></div>
|
<div class="map" v-if="p.geo" ref="map"></div>
|
||||||
<div class="repost" v-if="p.repost">
|
<div class="repost" v-if="p.repost">
|
||||||
<mk-post-preview :post="p.repost"/>
|
<mk-post-preview :post="p.repost"/>
|
||||||
|
@ -157,7 +157,7 @@ export default Vue.extend({
|
||||||
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
||||||
if (shouldShowMap) {
|
if (shouldShowMap) {
|
||||||
(this as any).os.getGoogleMaps().then(maps => {
|
(this as any).os.getGoogleMaps().then(maps => {
|
||||||
const uluru = new maps.LatLng(this.p.geo.latitude, this.p.geo.longitude);
|
const uluru = new maps.LatLng(this.p.geo.coordinates[1], this.p.geo.coordinates[0]);
|
||||||
const map = new maps.Map(this.$refs.map, {
|
const map = new maps.Map(this.$refs.map, {
|
||||||
center: uluru,
|
center: uluru,
|
||||||
zoom: 15
|
zoom: 15
|
||||||
|
|
|
@ -224,8 +224,7 @@ export default Vue.extend({
|
||||||
repostId: this.repost ? this.repost.id : undefined,
|
repostId: this.repost ? this.repost.id : undefined,
|
||||||
poll: this.poll ? (this.$refs.poll as any).get() : undefined,
|
poll: this.poll ? (this.$refs.poll as any).get() : undefined,
|
||||||
geo: this.geo ? {
|
geo: this.geo ? {
|
||||||
latitude: this.geo.latitude,
|
coordinates: [this.geo.longitude, this.geo.latitude],
|
||||||
longitude: this.geo.longitude,
|
|
||||||
altitude: this.geo.altitude,
|
altitude: this.geo.altitude,
|
||||||
accuracy: this.geo.accuracy,
|
accuracy: this.geo.accuracy,
|
||||||
altitudeAccuracy: this.geo.altitudeAccuracy,
|
altitudeAccuracy: this.geo.altitudeAccuracy,
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<div class="tags" v-if="p.tags && p.tags.length > 0">
|
<div class="tags" v-if="p.tags && p.tags.length > 0">
|
||||||
<router-link v-for="tag in p.tags" :key="tag" :to="`/search?q=#${tag}`">{{ tag }}</router-link>
|
<router-link v-for="tag in p.tags" :key="tag" :to="`/search?q=#${tag}`">{{ tag }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.latitude},${p.geo.longitude}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.coordinates[1]},${p.geo.coordinates[0]}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
||||||
<div class="map" v-if="p.geo" ref="map"></div>
|
<div class="map" v-if="p.geo" ref="map"></div>
|
||||||
<div class="repost" v-if="p.repost">
|
<div class="repost" v-if="p.repost">
|
||||||
<mk-post-preview :post="p.repost"/>
|
<mk-post-preview :post="p.repost"/>
|
||||||
|
@ -169,7 +169,7 @@ export default Vue.extend({
|
||||||
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
||||||
if (shouldShowMap) {
|
if (shouldShowMap) {
|
||||||
(this as any).os.getGoogleMaps().then(maps => {
|
(this as any).os.getGoogleMaps().then(maps => {
|
||||||
const uluru = new maps.LatLng(this.p.geo.latitude, this.p.geo.longitude);
|
const uluru = new maps.LatLng(this.p.geo.coordinates[1], this.p.geo.coordinates[0]);
|
||||||
const map = new maps.Map(this.$refs.map, {
|
const map = new maps.Map(this.$refs.map, {
|
||||||
center: uluru,
|
center: uluru,
|
||||||
zoom: 15
|
zoom: 15
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
</div>
|
</div>
|
||||||
<mk-poll v-if="p.poll" :post="p"/>
|
<mk-poll v-if="p.poll" :post="p"/>
|
||||||
<mk-url-preview v-for="url in urls" :url="url" :key="url"/>
|
<mk-url-preview v-for="url in urls" :url="url" :key="url"/>
|
||||||
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.latitude},${p.geo.longitude}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.coordinates[1]},${p.geo.coordinates[0]}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
||||||
<div class="map" v-if="p.geo" ref="map"></div>
|
<div class="map" v-if="p.geo" ref="map"></div>
|
||||||
<div class="repost" v-if="p.repost">
|
<div class="repost" v-if="p.repost">
|
||||||
<mk-post-preview :post="p.repost"/>
|
<mk-post-preview :post="p.repost"/>
|
||||||
|
@ -154,7 +154,7 @@ export default Vue.extend({
|
||||||
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
||||||
if (shouldShowMap) {
|
if (shouldShowMap) {
|
||||||
(this as any).os.getGoogleMaps().then(maps => {
|
(this as any).os.getGoogleMaps().then(maps => {
|
||||||
const uluru = new maps.LatLng(this.p.geo.latitude, this.p.geo.longitude);
|
const uluru = new maps.LatLng(this.p.geo.coordinates[1], this.p.geo.coordinates[0]);
|
||||||
const map = new maps.Map(this.$refs.map, {
|
const map = new maps.Map(this.$refs.map, {
|
||||||
center: uluru,
|
center: uluru,
|
||||||
zoom: 15
|
zoom: 15
|
||||||
|
|
|
@ -118,8 +118,7 @@ export default Vue.extend({
|
||||||
replyId: this.reply ? this.reply.id : undefined,
|
replyId: this.reply ? this.reply.id : undefined,
|
||||||
poll: this.poll ? (this.$refs.poll as any).get() : undefined,
|
poll: this.poll ? (this.$refs.poll as any).get() : undefined,
|
||||||
geo: this.geo ? {
|
geo: this.geo ? {
|
||||||
latitude: this.geo.latitude,
|
coordinates: [this.geo.longitude, this.geo.latitude],
|
||||||
longitude: this.geo.longitude,
|
|
||||||
altitude: this.geo.altitude,
|
altitude: this.geo.altitude,
|
||||||
accuracy: this.geo.accuracy,
|
accuracy: this.geo.accuracy,
|
||||||
altitudeAccuracy: this.geo.altitudeAccuracy,
|
altitudeAccuracy: this.geo.altitudeAccuracy,
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
<router-link v-for="tag in p.tags" :key="tag" :to="`/search?q=#${tag}`">{{ tag }}</router-link>
|
<router-link v-for="tag in p.tags" :key="tag" :to="`/search?q=#${tag}`">{{ tag }}</router-link>
|
||||||
</div>
|
</div>
|
||||||
<mk-url-preview v-for="url in urls" :url="url" :key="url"/>
|
<mk-url-preview v-for="url in urls" :url="url" :key="url"/>
|
||||||
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.latitude},${p.geo.longitude}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
<a class="location" v-if="p.geo" :href="`http://maps.google.com/maps?q=${p.geo.coordinates[1]},${p.geo.coordinates[0]}`" target="_blank">%fa:map-marker-alt% 位置情報</a>
|
||||||
<div class="map" v-if="p.geo" ref="map"></div>
|
<div class="map" v-if="p.geo" ref="map"></div>
|
||||||
<span class="app" v-if="p.app">via <b>{{ p.app.name }}</b></span>
|
<span class="app" v-if="p.app">via <b>{{ p.app.name }}</b></span>
|
||||||
<div class="repost" v-if="p.repost">
|
<div class="repost" v-if="p.repost">
|
||||||
|
@ -147,7 +147,7 @@ export default Vue.extend({
|
||||||
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
const shouldShowMap = (this as any).os.isSignedIn ? (this as any).os.i.account.clientSettings.showMaps : true;
|
||||||
if (shouldShowMap) {
|
if (shouldShowMap) {
|
||||||
(this as any).os.getGoogleMaps().then(maps => {
|
(this as any).os.getGoogleMaps().then(maps => {
|
||||||
const uluru = new maps.LatLng(this.p.geo.latitude, this.p.geo.longitude);
|
const uluru = new maps.LatLng(this.p.geo.coordinates[1], this.p.geo.coordinates[0]);
|
||||||
const map = new maps.Map(this.$refs.map, {
|
const map = new maps.Map(this.$refs.map, {
|
||||||
center: uluru,
|
center: uluru,
|
||||||
zoom: 15
|
zoom: 15
|
||||||
|
|
|
@ -136,16 +136,11 @@ props:
|
||||||
en: "Geo location"
|
en: "Geo location"
|
||||||
defName: "geo"
|
defName: "geo"
|
||||||
def:
|
def:
|
||||||
- name: "latitude"
|
- name: "coordinates"
|
||||||
type: "number"
|
type: "number[]"
|
||||||
optional: false
|
optional: false
|
||||||
desc:
|
desc:
|
||||||
ja: "緯度。-90〜90で表す。"
|
ja: "座標。最初に経度:-180〜180で表す。最後に緯度:-90〜90で表す。"
|
||||||
- name: "longitude"
|
|
||||||
type: "number"
|
|
||||||
optional: false
|
|
||||||
desc:
|
|
||||||
ja: "経度。-180〜180で表す。"
|
|
||||||
- name: "altitude"
|
- name: "altitude"
|
||||||
type: "number"
|
type: "number"
|
||||||
optional: false
|
optional: false
|
||||||
|
|
47
tools/migration/nighthike/5.js
Normal file
47
tools/migration/nighthike/5.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// for Node.js interpret
|
||||||
|
|
||||||
|
const { default: Post } = require('../../../built/api/models/post');
|
||||||
|
const { default: zip } = require('@prezzemolo/zip')
|
||||||
|
|
||||||
|
const migrate = async (post) => {
|
||||||
|
const result = await Post.update(post._id, {
|
||||||
|
$set: {
|
||||||
|
'geo.type': 'Point',
|
||||||
|
'geo.coordinates': [post.geo.longitude, post.geo.latitude]
|
||||||
|
},
|
||||||
|
$unset: {
|
||||||
|
'geo.longitude': '',
|
||||||
|
'geo.latitude': '',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result.ok === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const count = await Post.count({
|
||||||
|
'geo': { $ne: null }
|
||||||
|
});
|
||||||
|
|
||||||
|
const dop = Number.parseInt(process.argv[2]) || 5
|
||||||
|
const idop = ((count - (count % dop)) / dop) + 1
|
||||||
|
|
||||||
|
return zip(
|
||||||
|
1,
|
||||||
|
async (time) => {
|
||||||
|
console.log(`${time} / ${idop}`)
|
||||||
|
const doc = await Post.find({
|
||||||
|
'geo': { $ne: null }
|
||||||
|
}, {
|
||||||
|
limit: dop, skip: time * dop
|
||||||
|
})
|
||||||
|
return Promise.all(doc.map(migrate))
|
||||||
|
},
|
||||||
|
idop
|
||||||
|
).then(a => {
|
||||||
|
const rv = []
|
||||||
|
a.forEach(e => rv.push(...e))
|
||||||
|
return rv
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
main().then(console.dir).catch(console.error)
|
Loading…
Reference in a new issue