mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-03 23:14:13 +00:00 
			
		
		
		
	add: edit support on masto api
This commit is contained in:
		
							parent
							
								
									0d013ff54f
								
							
						
					
					
						commit
						f1c827b815
					
				
					 3 changed files with 62 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -800,13 +800,14 @@ export class MastodonApiServerService {
 | 
			
		|||
			const accessTokens = _request.headers.authorization;
 | 
			
		||||
			const client = getClient(BASE_URL, accessTokens);
 | 
			
		||||
			try {
 | 
			
		||||
				const data = await client.updateMedia(convertId(_request.params.id, IdType.SharkeyId), _request.body as any);
 | 
			
		||||
				const data = await client.updateMedia(convertId(_request.params.id, IdType.SharkeyId), _request.body!);
 | 
			
		||||
				reply.send(convertAttachment(data.data));
 | 
			
		||||
			} catch (e: any) {
 | 
			
		||||
				/* console.error(e); */
 | 
			
		||||
				reply.code(401).send(e.response.data);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
		NoteEndpoint.updateStatus();
 | 
			
		||||
 | 
			
		||||
		// DELETE Endpoint
 | 
			
		||||
		NoteEndpoint.deleteStatus();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -212,6 +212,21 @@ export class ApiStatusMastodon {
 | 
			
		|||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async updateStatus() {
 | 
			
		||||
		this.fastify.put<{ Params: { id: string } }>('/v1/statuses/:id', async (_request, reply) => {
 | 
			
		||||
			const BASE_URL = `${_request.protocol}://${_request.hostname}`;
 | 
			
		||||
			const accessTokens = _request.headers.authorization;
 | 
			
		||||
			const client = getClient(BASE_URL, accessTokens);
 | 
			
		||||
			try {
 | 
			
		||||
				const data = await client.editStatus(convertId(_request.params.id, IdType.SharkeyId), _request.body!);
 | 
			
		||||
				reply.send(convertStatus(data.data));
 | 
			
		||||
			} catch (e: any) {
 | 
			
		||||
				console.error(e);
 | 
			
		||||
				reply.code(_request.is404 ? 404 : 401).send(e.response.data);
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public async addFavourite() {
 | 
			
		||||
		this.fastify.post<{ Params: { id: string } }>('/v1/statuses/:id/favourite', async (_request, reply) => {
 | 
			
		||||
			const BASE_URL = `${_request.protocol}://${_request.hostname}`;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1147,12 +1147,53 @@ export default class Misskey implements MegalodonInterface {
 | 
			
		|||
      sensitive?: boolean
 | 
			
		||||
      media_ids?: Array<string>
 | 
			
		||||
      poll?: { options?: Array<string>; expires_in?: number; multiple?: boolean; hide_totals?: boolean }
 | 
			
		||||
      visibility?: "public" | "unlisted" | "private" | "direct"
 | 
			
		||||
    }
 | 
			
		||||
  ): Promise<Response<Entity.Status>> {
 | 
			
		||||
    return new Promise((_, reject) => {
 | 
			
		||||
      const err = new NoImplementedError('misskey does not support')
 | 
			
		||||
      reject(err)
 | 
			
		||||
    })
 | 
			
		||||
    let params = {
 | 
			
		||||
      editId: _id,
 | 
			
		||||
      text: _options.status
 | 
			
		||||
    }
 | 
			
		||||
    if (_options) {
 | 
			
		||||
      if (_options.media_ids) {
 | 
			
		||||
        params = Object.assign(params, {
 | 
			
		||||
          fileIds: _options.media_ids
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (_options.poll) {
 | 
			
		||||
        let pollParam = {
 | 
			
		||||
          choices: _options.poll.options,
 | 
			
		||||
          expiresAt: null,
 | 
			
		||||
          expiredAfter: _options.poll.expires_in
 | 
			
		||||
        }
 | 
			
		||||
        if (_options.poll.multiple !== undefined) {
 | 
			
		||||
          pollParam = Object.assign(pollParam, {
 | 
			
		||||
            multiple: _options.poll.multiple
 | 
			
		||||
          })
 | 
			
		||||
        }
 | 
			
		||||
        params = Object.assign(params, {
 | 
			
		||||
          poll: pollParam
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (_options.sensitive) {
 | 
			
		||||
        params = Object.assign(params, {
 | 
			
		||||
          cw: ''
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (_options.spoiler_text) {
 | 
			
		||||
        params = Object.assign(params, {
 | 
			
		||||
          cw: _options.spoiler_text
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
      if (_options.visibility) {
 | 
			
		||||
        params = Object.assign(params, {
 | 
			
		||||
          visibility: MisskeyAPI.Converter.encodeVisibility(_options.visibility)
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    return this.client
 | 
			
		||||
      .post<MisskeyAPI.Entity.CreatedNote>('/api/notes/edit', params)
 | 
			
		||||
      .then(res => ({ ...res, data: MisskeyAPI.Converter.note(res.data.createdNote, this.baseUrl) }))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue