using JiDangJia.Contracts; using Microsoft.Data.Sqlite; using static JiDangJia.Server.ServerStore; namespace JiDangJia.Server; public sealed partial class CommunityStore { private static PublishLocation LocationFor(SqliteConnection c,Account actor,PublishPostRequest request,long? editing) { // A publication's original location is immutable when editing or retrying it. var old=editing.HasValue?Rows(c,"SELECT locationJson FROM CommunityPosts WHERE id=@p0 AND authorId=@p1",editing.Value,actor.Id).FirstOrDefault():Rows(c,"SELECT locationJson FROM CommunityPosts WHERE clientId=@p0 AND authorId=@p1",request.ClientId,actor.Id).FirstOrDefault(); var existing=old is null?null:ReadJson(Text(old,"locationJson")); if(existing is not null)return existing; var value=request.Location??throw new ArgumentException("请升级 APP 并开启定位,发布位置必须由手机自动获取"); if(value.IsMock||!double.IsFinite(value.Latitude)||!double.IsFinite(value.Longitude)||value.Latitude is < -90 or >90||value.Longitude is < -180 or >180||value.Latitude==0&&value.Longitude==0)throw new ArgumentException("发布位置无效,请关闭模拟位置并重新定位"); if(!double.IsFinite(value.Accuracy)||value.Accuracy is <=0 or >1000||value.RecordedAtDateTimeOffset.UtcNow.AddMinutes(2))throw new ArgumentException("定位已过期或精度不足,请重新获取位置"); var city=Input(value.City,60,"定位城市");var area=(value.Area??"").Trim();if(area.Length>120||area.Any(char.IsControl))throw new ArgumentException("定位区域无效"); // Caller-supplied legacy City/Address fields cannot override the GPS-derived label. return value with{City=city,Area=area}; } }